在java中加载mp3文件时遇到问题无法从输入文件获取音频输入流

发布于 2024-12-22 21:11:42 字数 426 浏览 5 评论 0原文

我有以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心小果奶 2024-12-29 21:11:42

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

櫻之舞 2024-12-29 21:11:42

答案可以在 JavaSound 标签信息中找到。页面(我添加到问题中的标签)。特别要注意以下部分:

  1. 服务提供者接口
  2. Java 声音功能
  3. MP3 解码支持

第一部分描述了 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:

  1. Service Provider Interface
  2. Java Sound Capabilities
  3. MP3 decoding support

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 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文