Video on Doja example
Last week I had to test if some video in .3gp format worked on a particular handset, but I wanted to test it from a Doja app. Given that someone on doja-developer.net asked for it as well, I coded a quick example, quite similar my other JarInflater example, and here it is.
If your video lasts more than a few seconds, it will probably not fit in the 30KB .jar file, so I guess this should get the video from the network. I’ll leave that as an exercise for the reader…
/*** 10:31 4/18/2005* Miguel de Benito Delgado <nonick AT 8027 DOT org>** This little app demonstrates how to load and display a video.**/import com.nttdocomo.ui.*;import javax.microedition.io.Connector;import java.io.InputStream;/****/public class VideoTest extends IApplication implements ComponentListener, MediaListener{Panel dialog;Label label;Button buttonPlay;Button buttonStop;Button buttonExit;VisualPresenter player;/*** Application's entry point.*/public void start(){try {// Open the fileInputStream is = Connector.openInputStream("resource:///video.3gp");/// And use it as usual.MediaImage img = MediaManager.getImage(is);img.use();is.close();/// This component will play the fileplayer = new VisualPresenter();player.setImage(img);/// Build the paneldialog = new Panel();label = new Label("video.3gp");buttonPlay = new Button("Play");buttonStop = new Button("Stop");buttonExit = new Button("Exit");HTMLLayout layout = new HTMLLayout();dialog.setLayoutManager(layout);dialog.setTitle("Video Player");layout.begin(HTMLLayout.CENTER);dialog.add(label);layout.br();dialog.add(player);layout.br();dialog.add(buttonPlay);dialog.add(buttonStop);layout.br();dialog.add(buttonExit);layout.end();///// Set the focus at the play buttonbuttonPlay.requestFocus();// Set ourselves as main Frame for the displayDisplay.setCurrent(dialog);// Set ourselves as listener for events fired by the components in the paneldialog.setComponentListener(this);}// Not very sofisticated error handling...catch (Exception e) {System.out.println("ooops: " + e.toString());terminate();}}/*** Listen to events generated by the buttons.*/public void componentAction(Component source, int type, int param){try {if (source == buttonPlay && type == BUTTON_PRESSED) {System.out.println("Play");player.play();} else if (source == buttonStop && type == BUTTON_PRESSED) {System.out.println("Stop");player.stop();} else if (source == buttonExit && type == BUTTON_PRESSED) {System.out.println("Exit");terminate();}} catch (Exception e) {System.out.println("Exception caught in componentAction(): " + e.toString());}}/*** Listen to events generated by the VisualPresenter*/public void mediaAction(MediaPresenter source, int type, int param){if (source == player && type == VisualPresenter.VISUAL_PLAYING) {System.out.println("Playing.");label.setText("Playing...");} else if (source == player && type == VisualPresenter.VISUAL_COMPLETE) {System.out.println("End of file.");label.setText("Finished.");} else if (source == player && type == VisualPresenter.VISUAL_STOPPED) {System.out.println("Stopped.");label.setText("Stopped.");}}}- Download this code: VideoTest.java

