Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
mindaxi
Posts: 31
Registered: ‎09-08-2009
My Device: Not Specified

Playing video on simultor

Hello all,

 

I am new to BB development. I created one sample application which will play video on simultor, but it did not work, the I try to find the solution in the forum, then I found that http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/1089414/How_To... So I copy it to test.but I still did not get it. I hopr someone could help me out, Here is the codes I used:

 

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://java.sun.com/products/java-media/mma/media/test-wav.wav");
            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());
        }
    }
}

 

By the way, I can open the file from the Browser of simultor, and I use eclipse JDE4.6 and simultor 9000. please help me , I worked for the problem for three days, excusez my poor English, thank you advance.

Please use plain text.
New Developer
mindaxi
Posts: 31
Registered: ‎09-08-2009
My Device: Not Specified

Re: Playing video on simultor

Nobody knows? or it is not clear, by the way I always get the wrong message"NullPointerException ".

 

Thank you advance

Lucas

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Playing video on simultor

You ahve to drilldown to find which line of code is throwing Nullpointer Exception.

Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
New Developer
mindaxi
Posts: 31
Registered: ‎09-08-2009
My Device: Not Specified

Re: Playing video on simultor

thanks BBDeveloper, thank u very much for your reply. I test it with the url, and when I press the button"space", I heard the voice of the file, but just the voice, the screen stay in the welcome screen, there is not the interface of the media player. not like the same test I did with the app brower. Could u tell me it is nomal? then I turn to test video from the server, I got the new problem, I can put the video in the SD Card of the simulator and I could play it there, But when I put the same video in the server, I cant play it from neither the brower of the simulator nor the app I wrote,  I got the message that HTTP Error413: Resquest Entity Too Large. I then tested it in the brower of my pc and I can played it from there. So I wonder if there is some limite for the video played in the simulator. and could u give me some link for testing, sorry to disturb u for these . thanks in advance.

 

Please use plain text.
Developer
gercoder
Posts: 46
Registered: ‎06-11-2009
My Device: Bold 2 - Pearl 8120

Re: Playing video on simultor

Hi Lucas,

 

          You can put a video in the source of your app and change your URL for.

             

               InputStream in = getClass().getResourceAsStream(this.VIDEO_NAME);
              player = Manager.createPlayer(in,"video/3gpp");

I test this with a 3gp video and it works, but sometime the simulator don't have the necessaries codecs.

 

Regards,

 

Mónica

If your issue is resolved, please mark this thread as solved. Click "Accept as solution" on the post that contains the answer to your question.
Please use plain text.
New Developer
mindaxi
Posts: 31
Registered: ‎09-08-2009
My Device: Not Specified

Re: Playing video on simultor

Thanks for your reply, Mónica. I work on a projet that need to get video from server, but I try your way and here is the code I used

         InputStream is = getClass().getResourceAsStream("/test.3gp");
         player = Manager.createPlayer(is,"video/3gpp");

but it did not work , By the way what u mean by "the source of my app", can u tell me more clearly,I use the video like the picture file I used before, just pull it into my package, (I use the eclipse) . sorry for this rookie's question, thanks in advance

 

Lucas

Please use plain text.
Developer
gercoder
Posts: 46
Registered: ‎06-11-2009
My Device: Bold 2 - Pearl 8120

Re: Playing video on simultor

Lucas,

 

By the way what u mean by "the source of my app", can u tell me more clearly,I use the video like the picture file I used before, just pull it into my package, (I use the eclipse)

 

         Yes into a package, its okay,  what problem do you have with it?, it throws an exception?

 

 

If your issue is resolved, please mark this thread as solved. Click "Accept as solution" on the post that contains the answer to your question.
Please use plain text.
New Developer
mindaxi
Posts: 31
Registered: ‎09-08-2009
My Device: Not Specified

Re: Playing video on simultor

thanks for your reply, I try my code in the simulator, but the problem is there is no image for the video in the screen of simulator, just the voice and by the way. I did not see the interface of the media player. is it normal?

Please use plain text.
Developer
gercoder
Posts: 46
Registered: ‎06-11-2009
My Device: Bold 2 - Pearl 8120

Re: Playing video on simultor

No, it isn't not common, maybe the problem are the codecs, try with other video.

 

Read this    http://www.blackberry.com/btsc/search.do?cmd=displayKC&docType=kc&externalId=KB05482

 

But sometimes the simulator doesn't have all the codecs.

 

Regards,

If your issue is resolved, please mark this thread as solved. Click "Accept as solution" on the post that contains the answer to your question.
Please use plain text.