在BlackBerry上播放实时视频流时出现“不支持的类型”

时间:2010-12-31 07:31:11

标签: blackberry

我正试图在我的黑莓设备上播放来自ip camera的实时视频。 尝试播放视频时,我收到了不受支持的类型异常。

package com.bb.play;

import javax.microedition.media.Player;
import javax.microedition.media.Manager;
import javax.microedition.media.control.VideoControl;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.system.Characters;

/**
 * 
 */
public final class PlayVideo extends UiApplication
{    

    private Player player;
    private VideoControl videoControl;


    public static void main(String[] args)
    {
            PlayVideo theApp = new PlayVideo();
            theApp.enterEventDispatcher();
    }

    public PlayVideo()
    {
        MainScreen ms = new MainScreen(){

            public boolean onClose()
            {
                //Clean up the player resources.
                player.close();
                videoControl.setVisible(false);
                close();
                return true;
            }

            //Override keyChar to capture key commands used to control video playback.
            protected boolean keyChar(char c, int status, int time)
            {
                boolean retVal = false;

                if (c == Characters.SPACE)
                {
                    if (player.getState() == Player.STARTED)
                    {
                        //Stop playback.
                        try
                        {
                            player.stop();
                        }
                        catch (Exception ex)
                        {
                            System.out.println("Exception: " + ex.toString());
                        }
                    }
                    else
                    {
                        //Start playback.
                        try
                        {
                            player.start();
                        }
                        catch (Exception ex)
                        {
                            System.out.println("Exception: " + ex.toString());
                        }
                    }

                    retVal = true;
                }

                return retVal;
            }
        };

        ms.setTitle(new LabelField("Let's play some video..."));
        LabelField lf = new LabelField("Press space to start/stop/resume playback.");
        ms.add(lf);
        pushScreen(ms);

        try
        {
            //Create a new Player pointing to the video file.
            //This can use any valid URL.
            player = Manager.createPlayer("http://camera1.mairie-brest.fr/axis-cgi/mjpg/video.cgi");
            player.realize();

            //Create a new VideoControl.
            videoControl = (VideoControl)player.getControl("VideoControl");
            //Initialize the video mode using a Field.
            videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");

            //Set the video control to be visible.
            videoControl.setVisible(true);
        }
        catch (Exception ex)
        {
            System.out.println(ex.toString());
        }
    }
} 

1 个答案:

答案 0 :(得分:1)

我也在尝试从Blackberry手机上的IP摄像头播放实时视频,并面临同样的问题。当我提供liveview url或指向远程服务器中托管的视频文件的链接时,Manager.createPlayer(url)正在抛出MediaException。但是,当我尝试从手机内存播放视频文件时,没有抛出这样的异常。这可能与Player API有关。

我的方法是从HttpConnection打开一个InputStream到liveview url,并连续从InputStream读取JPEG数据。这适用于诺基亚手机,但不适用于黑莓手机。 InputStream部分的读取数据不起作用。我在Blackberry开发者论坛上发布了一个查询,但还没有得到满意的解决方案。

http://supportforums.blackberry.com/t5/Java-Development/How-to-read-a-continous-multipart-data-stream-over-network-in/m-p/656629

我实施的工作解决方案是连续捕捉来自相机的JPEG快照(而不是您正在使用的MJPEG链接),并在Blackberry屏幕上绘制相同的快照。缺点是刷新率非常低,因为这涉及到一个接一个地打开和关闭HttpConnection。

希望我的回复很有用。如果您能够解决问题,请发帖。

Jithin