想写个JAVA的MP3音乐管理器,使用JMF插件,但发现运行时总报一个异常:
Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 16000.0 frame rate, FrameSize=32768 bits
Failed to realize: com.sun.media.PlaybackEngine@1808009
Error: Unable to realize com.sun.media.PlaybackEngine@1808009
不知道为什么,在网上寻找答案,忙了一天也找不到正解,不过最后在努力之下,终于成功。
步骤如下:
1.首先重装jdk,下最新安装版的。然后把环境变量配好,确保java能够运行。(不要用以前已安装好的,然后改一下环境变量路径,那样不行,好像找不到注册表。一定要重新安装)
2.安装jmf,安装到jre下。
3.重起电脑后安装jmf mp3插件,也是安装到jre下
4.在CMD中运行java com.sun.media.codec.audio.mp3.JavaDecoder测试能否成功
5. File f=new File("e:/a.mp3");
Player p=Manager.createRealizedPlayer(f.toURI().toURL());
p.prefetch();
p.start();
6.终于成功!
附
JMF的下载地址:http://www.oracle.com/technetwork/java/javase/download-142937.html
JMF API的下载地址:http://www.oracle.com/technetwork/java/javase/index-142695.html
JMF MP3 Plugin下载地址:http://www.oracle.com/technetwork/java/javase/download-137625.html
程序代码:
<span style="font-size:14px;">import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;public class Test {public static void main(String[] args) {try {File f=new File("e:/b.mp3");Player p=Manager.createRealizedPlayer(f.toURI().toURL());p.prefetch();p.start();} catch (NoPlayerException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (CannotRealizeException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (MalformedURLException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
}</span>
测试成功