Java Me视频播放器通过http - MediaException实现错误

时间:2012-05-22 08:11:43

标签: java-me video-streaming midp mmapi

我使用以下代码(来自http://www.java-tips.org/java-me-tips/midp/playing-video-on-j2me-devices.html的引用)。它失败了'实现()',javax.microedition.media.MediaException,"无法创建原生播放器"。这有什么问题?
我使用Eclipse和Netbeans尝试了这个。我错过了一些"互联网"权限或使用任何不正确的编码,视频是外部的&#mp;' test-resource,通过桌面浏览器下载时工作正常。

public void run()
{
    String url = "http://www.fileformat.info/format/mpeg/sample/05e7e78068f44f0ea748855ef33c9f4a/MELT.MPG";

    //Append the GUI to a form
    Form form = new Form("Video on java mobile!");
    Display display = Display.getDisplay(this);
    display.setCurrent(form);

    try
    {
        HttpConnection conn = (HttpConnection)Connector.open(url, 
            Connector.READ_WRITE);
        InputStream is = conn.openInputStream();

        Player p = Manager.createPlayer(is,"video/mpeg");
        //I tried the below, but that didn't work either
        //Player p = Manager.createPlayer(url);
        p.realize();

        //Get the video controller
        VideoControl video = (VideoControl) p.getControl("VideoControl");
        if(video != null) 
        {
            //Get a GUI to display the video
            Item videoItem = (Item)video.initDisplayMode(
            VideoControl.USE_GUI_PRIMITIVE, null);

            form.append(videoItem);
        }

        //Start the video          
        p.prefetch();
        p.start();
    }
    catch(Exception e)
    {
        form.append(url + " Error:" + e.getMessage());
    }

}

我刚刚开始使用Java,Eclipse,Netbeans。因为,到处都有类似的样本,我相信我遗漏了一些非常基本的东西。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

这里的问题是视频文件。虽然我的源视频似乎是“mpeg”,但模拟器无法接受。经过一番搜索,我发现了一个转换器,我手动将一些样本mp4转换为“mpeg”。在我尝试下载并播放这些手动转换的文件后,它最终使用了相同的模拟器。

如果您是新的J2ME / JavaME应用程序(像我一样),请继续使用输入数据源/格式和模拟器。切换仿真器或输入数据格式是识别不那么明显问题的简单方法。