javax.sound.sampled.LineUnavailableException:系统不支持指定的格式
javax.sound.sampled.LineUnavailableException: The system does not support the specified format
我正在探索录音 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);
}
谢谢
据我所知,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()
的 Javadoc:
Obtains an array of mixer info objects that represents the set of audio
mixers that are currently installed on the system.
我正在探索录音 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);
}
谢谢
据我所知,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()
的 Javadoc:
Obtains an array of mixer info objects that represents the set of audio mixers that are currently installed on the system.