我下载了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 ));
}
}
为什么我会得到这些异常?是不是代码有问题。