为什么我的音频不能再在Windows 10 PC上播放?

时间:2020-03-05 22:50:25

标签: java

我遇到了奇怪的音频播放问题。我的代码在开发它的Mac上完美运行,并在本周部署它的Windows 10 PC上运行。我不知道对这些Windows PC所做的任何更改。

我的开发Mac和Windows PC都安装了OpenJDK 11.0.2。当代码现在在Windows PC上运行时,我会收到以下异常:

Exception in thread "main" java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian is supported.
        at java.desktop/javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:425)
        at bob.Player.play(Player.java:26)
        at bob.Player.main(Player.java:57)

我用作测试的代码是:

URL audioUrl = new URL("https://(server FQDN)/audiopath/test.wav");
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioUrl);
AudioFormat format = audioStream.getFormat();
//AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 1, 2, 44100, false);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
SourceDataLine audioLine = (SourceDataLine) AudioSystem.getLine(info);
audioLine.open(format);
audioLine.start();
byte[] bytesBuffer = new byte[4096];
int bytesRead = -1; 
while ((bytesRead = audioStream.read(bytesBuffer)) != -1) {
    audioLine.write(bytesBuffer, 0, bytesRead);
}
audioLine.drain();
audioLine.close();
audioStream.close();

我尝试手动设置音频参数,而不是使用getFormat(),但这没什么区别。

有人知道为什么Windows 10无法播放此音频吗?直到上周,代码运行良好。

谢谢, 鲍伯

0 个答案:

没有答案