I can not start the player in my code

99封情书 提交于 2019-12-23 04:45:59

问题


I am trying to launch my my code and start the player. But I can not do that.

import javax.media.*;
import java.io.*;

public class MP3Player {

    public static void main(String[] args) throws Exception {
       File file = new File("c://player/trigger.mpg");
       MediaLocator mrl = new MediaLocator(file.toURL());
       Player player = Manager.createPlayer(mrl);
       player.start();
    }

}

[Edit by Philipp] According to a comment by the original author, Netbeans prints the following error message:

Unable to handle format: MPEG, 160x120, FrameRate=30.0, Length=28800 Failed to realize:
com.sun.media.PlaybackEngine@131f71a Error: Unable to realize
com.sun.media.PlaybackEngine@131f71a BUILD SUCCESSFUL (total time: 1 second)

[/Edit by Philipp]


回答1:


I don't know JMF player at all, but I assume the problem is that the code exits immediately after issuing the command, terminating any other threads...

I'd try inserting a Thread.sleep(1000); after player.start(); :

public class MP3Player {
    public static void main(String[] args) throws Exception 
    {    
        File file = new File("c:/player/trigger.mpg");    
        MediaLocator mrl = new MediaLocator(file.toURL());    
        Player player = Manager.createPlayer(mrl);    
        player.start(); 
        Thread.sleep(1000);
    } 
}

If now the first second of the MP3 is heard, this was the issue.

EDIT Also, someone pointed out problems with the slashes, the path should be correct too, but the slash is not missing, but there is rather one too much of it...

EDIT2 Ok, I misread mpg for mp3, and as the poster posted the error he got: the format of the video is not supported by JMF, you need a codec.

This might be of help: Tek-tips: Play MPEG-4 movie with JMF?




回答2:


Unable to handle format: MPEG, 160x120, FrameRate=30.0 It is unable to play a video stream it founds. From the description and the name of your code, the file is expected to contain only audio streams of the compression format MP3 (MPEG-1 Audio Layer III). An .mpg extension may contains lot of different mpeg formats



来源:https://stackoverflow.com/questions/12802134/i-can-not-start-the-player-in-my-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!