1

我想video streaming in java使用 rtsp url 来实现我。在设备上测试代码时,我得到 Media Exception 声明Prefetch Error-33。这是我的代码

    private void startStreaming()
    {
      try 
      {
        mplayer=Manager.createPlayer(videourl);

        mplayer.addPlayerListener(this);

        mplayer.realize();

        videoControl=(VideoControl) mplayer.getControl("VideoControl");

        if(videoControl!=null)
        {
            Item video=(Item) videoControl.initDisplayMode(videoControl.USE_GUI_PRIMITIVE, null);

            videoControl.setVisible(true);

            System.out.println("Playing");

            Form v=new Form("Playing Video");

            StringItem si=new StringItem("Status", "Playing....");

            v.append(video);

            display.setCurrent(v);
        }

        mplayer.prefetch();

        mplayer.start();
    } 

    catch(Exception noCanDo)
    {
        Form f=new Form("Error");

        f.append("Error : "+noCanDo);

        display.setCurrent(f);
    }
}

我也尝试过使用 MIDlet.platformrequest(videourl) 方法的替代方法,该方法调用设备的默认内部播放器来播放视频文件。播放器正在启动,但稍后connection timeout会出现提示。然而,我已经测试了 rtsp url,它工作得非常好。关于如何在 java me 中使用 rtsp url 进行视频流的任何建议?

4

1 回答 1

0

将此代码用于流式 RTSP,它应该适用于 nokia symbian belle sdk 1.1 和 nokia sdk 2.0

protected void startApp() throws MIDletStateChangeException {
        VideoCanvas VC = new VideoCanvas(this,url); 
        Display.getDisplay(this).setCurrent(VC); }

    }
    //videoCanvas Class

    public VideoCanvas(ExampleStreamingMIDlet midlet, String url) {
            this.midlet = midlet;
            this.url = url;
            addCommand(start);
            addCommand(stop);
            addCommand(back);
            addCommand(exit);
            setCommandListener(this);
            this.setFullScreenMode(true);
        }

    public void commandAction(Command c, Displayable arg1) {
            if(c == start) {
                start();
            }




    public void start() {
            try{

               Player player = Manager.createPlayer(url);
                player.addPlayerListener(this);
               player.realize();


                control = (VideoControl)player.getControl("VideoControl");
                if (control != null) {
                    control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this);
                    control.setDisplaySize(176,144);
                    int width = control.getSourceWidth();
                    int height = control.getSourceHeight();
                    status2 = "Before: SW=" + width + "-SH=" + height + "-DW=" + control.getDisplayWidth() + "-DH=" + control.getDisplayHeight();
                }

                player.start();
            }
            catch(Exception e) {
                Alert erro = new Alert("Erro",e.getMessage(),null,AlertType.ERROR);
                Display.getDisplay(midlet).setCurrent(erro);
            }
        }

    public void stop() {
            if(player != null) {
                player.deallocate();
                player.close();
            }
        }
于 2012-08-27T10:59:39.627 回答