开发者

"Unsupported Type" when playing live video stream on BlackBerry

开发者 https://www.devze.com 2023-02-02 10:03 出处:网络
I am trying to play live video from an ip camera on my blackberry device. I am getting an unsupported type exception when trying to play the video.

I am trying to play live video from an ip camera on my blackberry device. I am getting an unsupported type exception when trying to play the video.

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)
     开发者_JAVA百科       {
                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());
        }
    }
} 


I am also trying to play live video from an IP camera on Blackberry phone and face the same problem. Manager.createPlayer(url) is throwing MediaException, when I give a liveview url or a link to a video file hosted in a remote server. However, there is no such exception thrown, when I try playing a video file from the phone memory. This is probably related to the Player API.

My approach is to open an InputStream from an HttpConnection to the liveview url and to read JPEG data from the InputStream continously. This worked in Nokia phones, but not in Blackberry. The reading data from InputStream part is not working. I have posted a query at the Blackberry developer forum, but haven't got a satisfactory solution yet.

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

A working solution which I have implemented is to capture JPEG snapshots from the camera continuously (instead of the MJPEG link you are using) and to draw the same on the Blackberry screen. The drawback is that the refresh rate is very low, because this involves opening and closing HttpConnection one after another.

Hope my reply was useful. Please do post when you are able to solve the issue.

Jithin

0

精彩评论

暂无评论...
验证码 换一张
取 消