[英]Why do i get these exceptions while trying to play a mp3 file?
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. 我下载了JMF MP3插件来播放Java程序中的mp3文件,
mp3plugin.jar
与JDK一起包含在netbeans项目库中。 But still i am unable to play mp3 file. 但我仍然无法播放mp3文件。 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
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.
代码有问题吗?
I refer you to this link for an example. 我以这个链接为例。
http://blogs.oracle.com/kashmir/entry/java_sound_api_2_mp3 http://blogs.oracle.com/kashmir/entry/java_sound_api_2_mp3
Basically the MP3 plugin can read in MP3s, but not play them. 基本上,MP3插件可以读取MP3,但不能播放它们。 In order to play them you must convert them in the program to a file type that can actually be played such as PCM.
为了播放它们,您必须将它们在程序中转换为可以实际播放的文件类型,例如PCM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.