2

我正在使用以下代码(来自http://www.java-tips.org/java-me-tips/midp/playing-video-on-j2me-devices.html的引用)。它在 'realize()' 处失败javax.microedition.media.MediaException,出现“无法创建本机播放器”。这里有什么问题?
我使用 Eclipse 和 Netbeans 都试过了。我是否缺少一些“互联网”权限或使用了任何不正确的编码,视频是外部“mpg”测试资源,通过桌面浏览器下载时可以正常工作。

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。因为到处都有类似的样本,我相信我错过了一些非常基本的东西。有人可以帮忙吗?

4

1 回答 1

0

这里的问题是视频文件。虽然我的源视频看起来像是“mpeg”,但模拟器无法接受。经过一番搜索,我找到了一个转换器,我手动将一些示例 mp4 转换为“mpeg”。在我尝试下载和播放这些手动转换的文件之后,它终于可以在同一个模拟器上工作了。

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

于 2012-06-12T11:12:03.073 回答