为什么我在尝试播放 mp3 文件时会出现这些异常?

发布于 2024-11-27 05:52:15 字数 1468 浏览 2 评论 0原文

我下载了 JMF MP3 插件 在我的 java 中播放 mp3 文件我将 mp3plugin.jar 与 JDK 一起包含在我的 netbeans 项目库中。但我仍然无法播放 mp3 文件。 当我运行代码时,出现以下异常:

Exception in thread "main" javax.sound.sampled.LineUnavailableException: line with format MPEG1L3 44100.0 Hz, unknown bits per sample, stereo, unknown frame size, unknown frame rate,  not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:541)
at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1341)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:124)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1121)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1211)
at mp3.MP3.main(MP3.java:25)
Java Result: 1

这是我编写的用于播放 MP3 文件的代码

import javax.sound.sampled.*;
import java.io.*;

public class MP3 {
 static Thread th;

public static void main(String[] args) throws Exception {
     Clip clip = AudioSystem.getClip();
     AudioInputStream ais = AudioSystem.getAudioInputStream(new File("mysong.mp3"));
     clip.open(ais);
     clip.loop(0);
     long tf = (long)(clip.getFrameLength() * clip.getFormat().getFrameRate());           
     Thread.sleep( ( tf* 1000 ));          
}

}

为什么会出现这些异常?是不是代码有问题。

I downloaded JMF MP3 Plugin to play mp3 files in my java program.I included mp3plugin.jar in my project library of netbeans along with JDK. But still i am unable to play mp3 file.
When i run my code i get the following exception :

Exception in thread "main" javax.sound.sampled.LineUnavailableException: line with format MPEG1L3 44100.0 Hz, unknown bits per sample, stereo, unknown frame size, unknown frame rate,  not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:541)
at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1341)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:124)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1121)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1211)
at mp3.MP3.main(MP3.java:25)
Java Result: 1

THIS IS THE CODE THAT I HAVE WRITTEN TO PLAY MP3 FILES

import javax.sound.sampled.*;
import java.io.*;

public class MP3 {
 static Thread th;

public static void main(String[] args) throws Exception {
     Clip clip = AudioSystem.getClip();
     AudioInputStream ais = AudioSystem.getAudioInputStream(new File("mysong.mp3"));
     clip.open(ais);
     clip.loop(0);
     long tf = (long)(clip.getFrameLength() * clip.getFormat().getFrameRate());           
     Thread.sleep( ( tf* 1000 ));          
}

}

Why do i get these exceptions ? Is there a problem with the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我的黑色迷你裙 2024-12-04 05:52:15

我建议您参考此链接作为示例。

http://blogs.oracle.com/kashmir/entry/java_sound_api_2_mp3

基本上是 MP3 插件可以读取 MP3,但不能播放。为了播放它们,您必须在程序中将它们转换为实际可以播放的文件类型,例如 PCM。

I refer you to this link for an example.

http://blogs.oracle.com/kashmir/entry/java_sound_api_2_mp3

Basically the MP3 plugin can read in MP3s, but not play them. In order to play them you must convert them in the program to a file type that can actually be played such as PCM.

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