10-08-2009 09:20 AM
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/li
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("Ex
}
}
else
{
//Start playback.
try
{
player.start();
}
catch (Exception ex)
{
System.out.println("Ex
}
}
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/
player.realize();
//Create a new VideoControl.
videoControl = (VideoControl)player.getControl("VideoControl");
//Initialize the video mode using a Field.
videoControl.initDisplayMode(VideoControl.USE_GUI_
//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.
10-08-2009 10:42 AM
Nobody knows? or it is not clear, by the way I always get the wrong message"NullPointerException ".
Thank you advance
Lucas
10-09-2009 03:04 AM
10-12-2009 11:57 AM
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.
10-12-2009 12:15 PM
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
10-12-2009 12:32 PM
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
10-12-2009 12:40 PM
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?
10-13-2009 04:26 AM
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?
10-13-2009 09:14 AM
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=displ
But sometimes the simulator doesn't have all the codecs.
Regards,