在java中加载mp3文件时遇到问题无法从输入文件获取音频输入流
我有以下代码:
String fileName="D:/downloads/song.mp3";
File soundFile = new File(fileName);
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
} catch (Exception ex) {
ex.printStackTrace();
}
但是该代码引发了以下异常:
javax.sound.sampled.UnsupportedAudioFileException:无法从输入文件获取音频输入流
如何解决此问题?
I have the following code:
String fileName="D:/downloads/song.mp3";
File soundFile = new File(fileName);
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
} catch (Exception ex) {
ex.printStackTrace();
}
But the code raises the following exception:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
How can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您缺少 MP3 编解码器。请参阅此线程 寻找可能的解决方案。他们提到了一个可能了解更多信息的 Java 声音邮件列表 - http://java .sun.com/products/java-media/sound/list.html
Sounds like you're missing an MP3 codec. See this thread for possible solutions. They mention a Java sound mailing list that might know more - http://java.sun.com/products/java-media/sound/list.html
答案可以在 JavaSound 标签信息中找到。页面(我添加到问题中的标签)。特别要注意以下部分:
第一部分描述了 JavaSound 系统(事实上许多 Java基于服务)提供给应用程序。第二个应该解释为什么你的代码对于 MP3 失败。第三个将提供一种向 JavaSound 添加 MP3 支持的方法。
顺便说一句 - 这与 有什么关系录音?
The answers are to be found in the JavaSound tag info. page (a tag I added to the question). Look particularly to the sections on:
The first describes how the JavaSound system (and in fact many Java based services) are provided to apps. The 2nd should explain why your code fails for MP3. The 3rd will offer a way to add MP3 support to JavaSound.
BTW - what does any of this have to do with audio-recording?