Video on Doja example

Saturday, April 23rd, 2005 - Español English

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… ;)

  1. /**
  2. * 10:31 4/18/2005
  3. * Miguel de Benito Delgado <nonick AT 8027 DOT org>
  4. *
  5. * This little app demonstrates how to load and display a video.
  6. *
  7. */
  8.  
  9. import com.nttdocomo.ui.*;
  10. import javax.microedition.io.Connector;
  11. import java.io.InputStream;
  12.  
  13. /**
  14. *
  15. */
  16. public class VideoTest extends IApplication implements ComponentListener, MediaListener
  17. {
  18. Panel dialog;
  19.  
  20. Label label;
  21. Button buttonPlay;
  22. Button buttonStop;
  23. Button buttonExit;
  24.  
  25. VisualPresenter player;
  26.  
  27. /**
  28. * Application's entry point.
  29. */
  30. public void start()
  31. {
  32. try {
  33. // Open the file
  34. InputStream is = Connector.openInputStream("resource:///video.3gp");
  35.  
  36. /// And use it as usual.
  37. MediaImage img = MediaManager.getImage(is);
  38. img.use();
  39. is.close();
  40.  
  41. /// This component will play the file
  42. player = new VisualPresenter();
  43. player.setImage(img);
  44.  
  45. /// Build the panel
  46. dialog = new Panel();
  47. label = new Label("video.3gp");
  48. buttonPlay = new Button("Play");
  49. buttonStop = new Button("Stop");
  50. buttonExit = new Button("Exit");
  51.  
  52. HTMLLayout layout = new HTMLLayout();
  53. dialog.setLayoutManager(layout);
  54.  
  55. dialog.setTitle("Video Player");
  56.  
  57. layout.begin(HTMLLayout.CENTER);
  58.  
  59. dialog.add(label);
  60.  
  61. layout.br();
  62.  
  63. dialog.add(player);
  64.  
  65. layout.br();
  66.  
  67. dialog.add(buttonPlay);
  68. dialog.add(buttonStop);
  69.  
  70. layout.br();
  71.  
  72. dialog.add(buttonExit);
  73.  
  74. layout.end();
  75.  
  76. ///
  77. // Set the focus at the play button
  78. buttonPlay.requestFocus();
  79.  
  80. // Set ourselves as main Frame for the display
  81. Display.setCurrent(dialog);
  82.  
  83. // Set ourselves as listener for events fired by the components in the panel
  84. dialog.setComponentListener(this);
  85. }
  86. // Not very sofisticated error handling...
  87. catch (Exception e) {
  88. System.out.println("ooops: " + e.toString());
  89. terminate();
  90. }
  91. }
  92.  
  93.  
  94. /**
  95. * Listen to events generated by the buttons.
  96. */
  97. public void componentAction(Component source, int type, int param)
  98. {
  99. try {
  100. if (source == buttonPlay && type == BUTTON_PRESSED) {
  101. System.out.println("Play");
  102. player.play();
  103. } else if (source == buttonStop && type == BUTTON_PRESSED) {
  104. System.out.println("Stop");
  105. player.stop();
  106. } else if (source == buttonExit && type == BUTTON_PRESSED) {
  107. System.out.println("Exit");
  108. terminate();
  109. }
  110. } catch (Exception e) {
  111. System.out.println("Exception caught in componentAction(): " + e.toString());
  112. }
  113. }
  114.  
  115.  
  116. /**
  117. * Listen to events generated by the VisualPresenter
  118. */
  119. public void mediaAction(MediaPresenter source, int type, int param)
  120. {
  121. if (source == player && type == VisualPresenter.VISUAL_PLAYING) {
  122. System.out.println("Playing.");
  123. label.setText("Playing...");
  124. } else if (source == player && type == VisualPresenter.VISUAL_COMPLETE) {
  125. System.out.println("End of file.");
  126. label.setText("Finished.");
  127. } else if (source == player && type == VisualPresenter.VISUAL_STOPPED) {
  128. System.out.println("Stopped.");
  129. label.setText("Stopped.");
  130. }
  131. }
  132. }
  133.  

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>