开发者

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. 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开发者_如何学JAVA 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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜