我开发了一种使用MP3 SPI播放MP3文件的服务,即使它在本机上运行良好,但在服务器上发布服务后却引发异常。这是记录器捕获的异常:
No line matching interface SourceDataLine supporting format PCM_SIGNED 16000.0
Hz, 16 bit, mono, 2 bytes/frame, little-endian, and buffers of -2 to -2 bytes
is supported.
以下是导致错误的代码段:
String url = "http://MusicURL.mp3"
AudioInputStream stream = null;
AudioInputStream dstream = null;
try {
URL urlFile = new URL(url);
stream = AudioSystem.getAudioInputStream(urlFile);
} catch (UnsupportedAudioFileException e) {
logger.error("...", e);
} catch (IOException e) {
logger.error("...", e);
}
if (stream!=null){
try {
AudioFormat baseFormat = stream.getFormat();
AudioFormat decodedFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false);
dstream = AudioSystem.getAudioInputStream(decodedFormat, stream);
SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat,
((int)dstream.getFrameLength()*decodedFormat.getFrameSize()));
SourceDataLine line = (SourceDataLine)AudioSystem.getLine(info);
我非常确定将我的项目上载到服务器容器时已包含MP3 SPI JAR软件包,似乎该错误发生在最后一行。谁能告诉我为什么它不起作用...需要帮助!