javax.sound.sampled.LineUnavailableException:系统不支持指定的格式

时间:2018-10-24 20:28:19

标签: java heroku javasound

我正在探索录音API。这在我的本地计算机上运行良好,但是一旦我在Heroku上部署了它,以下行就会引发异常:

 if (!AudioSystem.isLineSupported(info)) {
        throw new LineUnavailableException(
                "The system does not support the specified format.");
 }

文件格式为.wav。是在Heroku上没有声卡还是我缺少其他东西?

这是我要在Heroku上执行的代码段:

    format = getAudioFormat();
    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);

    // checks if system supports the data line
    if (!AudioSystem.isLineSupported(info)) {
        throw new LineUnavailableException(
                "The system does not support the specified format.");
    }

    audioLine = AudioSystem.getTargetDataLine(format);

    audioLine.open(format);
    audioLine.start();

    byte[] buffer = new byte[BUFFER_SIZE];
    int bytesRead = 0;

    recordBytes = new ByteArrayOutputStream();
    isRunning = true;

    while (isRunning) {
        bytesRead = audioLine.read(buffer, 0, buffer.length);
        recordBytes.write(buffer, 0, bytesRead);
    }

谢谢

1 个答案:

答案 0 :(得分:1)

据我所知Heroku不支持声音。 要确定找出来:

Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
for (Mixer.Info[] info : mixerInfos) {
    System.out.println("Supported: " + info);
}
if (mixerInfos.length == 0) {
    System.out.println("Audio mixers are not supported.");
}

摘自getMixerInfo()的Javadocs:

  

获取代表音频集的混音器信息对象数组   系统上当前安装的混音器。