protected void startApp() throws MIDletStateChangeException {
myDisplay.setCurrent(myForm);
streamingThread = new Thread(this);
}
protected void pauseApp() {}
protected void destroyApp(boolean unconditional) {
try {
myPlayer.stop();
myPlayer.close();
}
catch( Exception e ) {
log("Exception: " + e.toString());
}
}
/**
* Inits and starts the Player for Video Streaming
*/
private void startStreaming(){
try{
myPlayer = Manager.createPlayer("rtsp://MyServer/MyFile.3gp");
myPlayer.addPlayerListener(this);
myPlayer.realize();
// Grab the video control and set it to the current display.
vc = (VideoControl)myPlayer.getControl("VideoControl");
if (vc != null) {
myForm.append((Item)vc.initDisplayMode(vc.USE_GUI_PRIMITIVE, null));
// sets the display size of the video.
vc.setDisplaySize(120,160);
}
myPlayer.start();
}catch(Exception e){
log("Exception: " + e.toString());
}
}
public void commandAction(Command c, Displayable s){
if(c.getCommandType()==Command.EXIT){
running=false;
notifyDestroyed();
}else{
streamingThread.start();
}
}
/**
* PlayerListener Interface method, logs all player event.
*/
public void playerUpdate(Player player, String event, Object eventData){
log(" ** playerUpdate: " + event + " **");
}
public void log(String msg){
System.out.println(msg);
}
public void run() {
running=true;
startStreaming();
while(running){
Thread.yield();
}
}
}