nothing happens that is the problem.
when I press "stop" then it gives: java.lang.NullPointerException
and yes i did not give everything of the code
this is de full code:
Code:
package Video;
/*
* DisplayVideo.java
*
* Created on 15 juni 2006, 11:46
*/
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import java.io.*;
/**
*
* @author Gorsken
*/
public class DisplayVideo extends MIDlet implements CommandListener {
/** Creates a new instance of testMP3 */
public DisplayVideo() {
initialize();
}
private Form start;
private Command exit;
private Command video;
private Form playVideo;
private Command stop;
private Command play;
private Command Back;
private Player player;
/** Called by the system to indicate that a command has been invoked on a particular displayable.
* @param command the Command that ws invoked
* @param displayable the Displayable on which the command was invoked
*/
public void commandAction(Command command, Displayable displayable) {
// Insert global pre-action code here
if (displayable == start) {
if (command == video) {
// Insert pre-action code here
getDisplay().setCurrent(get_playVideo());
// Insert post-action code here
} else if (command == exit) {
// Insert pre-action code here
exitMIDlet();
// Insert post-action code here
}
} else if (displayable == playVideo) {
if (command == Back) {
// Insert pre-action code here
getDisplay().setCurrent(get_start());
// Insert post-action code here
} else if (command == play) {
// Insert pre-action code here
playerVideoStart();
// Insert post-action code here
} else if (command == exit) {
// Insert pre-action code here
exitMIDlet();
// Insert post-action code here
} else if (command == stop) {
// Insert pre-action code here
playerVideoStop();
// Insert post-action code here
}
}
// Insert global post-action code here
}
/** This method initializes UI of the application.
*/
private void initialize() {
// Insert pre-init code here
getDisplay().setCurrent(get_start());
// Insert post-init code here
}
/**
* This method should return an instance of the display.
*/
public Display getDisplay() {
return Display.getDisplay(this);
}
/**
* This method should exit the midlet.
*/
public void exitMIDlet() {
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
/** This method returns instance for start component and should be called instead of accessing start field directly.
* @return Instance for start component
*/
public Form get_start() {
if (start == null) {
// Insert pre-init code here
start = new Form("go and see video", new Item[0]);
start.addCommand(get_exit());
start.addCommand(get_video());
start.setCommandListener(this);
// Insert post-init code here
}
return start;
}
/** This method returns instance for exit component and should be called instead of accessing exit field directly.
* @return Instance for exit component
*/
public Command get_exit() {
if (exit == null) {
// Insert pre-init code here
exit = new Command("Exit", Command.EXIT, 1);
// Insert post-init code here
}
return exit;
}
/** This method returns instance for mp3 component and should be called instead of accessing mp3 field directly.
* @return Instance for mp3 component
*/
public Command get_video() {
if (video == null) {
// Insert pre-init code here
video = new Command("video", Command.OK, 1);
// Insert post-init code here
}
return video;
}
/** This method returns instance for music component and should be called instead of accessing music field directly.
* @return Instance for music component
*/
public Form get_playVideo() {
if (playVideo == null) {
// Insert pre-init code here
playVideo = new Form("playing the video", new Item[0]);
playVideo.addCommand(get_exit());
playVideo.addCommand(get_stop());
playVideo.addCommand(get_play());
playVideo.addCommand(get_Back());
playVideo.setCommandListener(this);
// Insert post-init code here
}
return playVideo;
}
/** This method returns instance for stopCommand1 component and should be called instead of accessing stopCommand1 field directly.
* @return Instance for stopCommand1 component
*/
public Command get_stop() {
if (stop == null) {
// Insert pre-init code here
stop = new Command("Stop", Command.STOP, 1);
// Insert post-init code here
}
return stop;
}
/** This method returns instance for play component and should be called instead of accessing play field directly.
* @return Instance for play component
*/
public Command get_play() {
if (play == null) {
// Insert pre-init code here
play = new Command("play", Command.OK, 1);
// Insert post-init code here
}
return play;
}
/** This method returns instance for Back component and should be called instead of accessing Back field directly.
* @return Instance for Back component
*/
public Command get_Back() {
if (Back == null) {
// Insert pre-init code here
Back = new Command("Back", Command.BACK, 1);
// Insert post-init code here
}
return Back;
}
public void playerVideoStart(){
try{
InputStream is = getClass().getResourceAsStream("/rotate.mpg");
player = Manager.createPlayer(is, "video/mpeg");
player.realize();
VideoControl vc = (VideoControl)player.getControl("VideoControl");
if (vc != null)
{
Item it =
(Item)vc.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,null);
playVideo.append(it);
player.start();
}
} catch (IOException ioe) {
} catch (MediaException me) { }
}
public void playerVideoStop(){
player.close();
}
public void startApp() {
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}