source code 2

  1. package com.ociweb.mmapi;
  2.  
  3. import java.io.IOException;
  4.  
  5. import javax.microedition.lcdui.*;
  6. import javax.microedition.media.*;
  7. import javax.microedition.media.control.*;
  8. import javax.microedition.midlet.*;
  9.  
  10. public class VideoMIDlet extends MIDlet implements CommandListener, PlayerListener {
  11. private Player videoPlayer;
  12. private List entryScreen;
  13. private Form busyForm = createBusyForm();
  14.  
  15. protected void startApp() throws MIDletStateChangeException {
  16. if (entryScreen == null) {
  17. entryScreen = new List("Video", List.IMPLICIT);
  18. entryScreen.append("Full screen", null);
  19. entryScreen.append("Window", null);
  20. entryScreen.setCommandListener(this);
  21. }
  22. Display.getDisplay(this).setCurrent(entryScreen);
  23. }
  24.  
  25. private void showDisplayInWindow() {
  26. Form videoForm = new Form("Please watch");
  27. videoForm.append("Check this out!");
  28. try {
  29. videoPlayer = Manager.createPlayer("http://localhost/Rabbit2004.mpg");
  30. videoPlayer.addPlayerListener(this);
  31. Display.getDisplay(this).setCurrent(busyForm);
  32. videoPlayer.realize();
  33. VideoControl videoControl = (VideoControl)videoPlayer.getControl("VideoControl");
  34. if (videoControl != null) {
  35. Item videoItem = (Item)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
  36. videoControl.setDisplaySize(75, 75);
  37. videoForm.append(videoItem);
  38. videoForm.append("Watch above");
  39. Display.getDisplay(this).setCurrent(videoForm);
  40. }
  41.  
  42. videoPlayer.start();
  43. } catch (IOException e) {
  44. e.printStackTrace();
  45. } catch (MediaException e) {
  46. e.printStackTrace();
  47. }
  48. }
  49.  
  50. private void showFullScreenDisplay() {
  51. Canvas canvas = new Canvas() {
  52. protected void paint(Graphics g) {
  53. // We won't draw anything ourselves
  54. }
  55. };
  56. Display.getDisplay(this).setCurrent(canvas);
  57. try {
  58. videoPlayer = Manager.createPlayer("http://localhost/Rabbit2004.mpg");
  59. videoPlayer.addPlayerListener(this);
  60. Display.getDisplay(this).setCurrent(busyForm);
  61. videoPlayer.realize();
  62. VideoControl videoControl = (VideoControl)videoPlayer.getControl("VideoControl");
  63. videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, canvas);
  64. videoControl.setVisible(true);
  65. videoPlayer.start();
  66. } catch (IOException e) {
  67. e.printStackTrace();
  68. } catch (MediaException e) {
  69. e.printStackTrace();
  70. }
  71. }
  72. protected void pauseApp() {
  73. stopPlayer();
  74. }
  75. private void stopPlayer() {
  76. try {
  77. videoPlayer.stop();
  78. } catch (MediaException e) {
  79. e.printStackTrace();
  80. }
  81. }
  82.  
  83. protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
  84. stopPlayer();
  85. }
  86. public void commandAction(Command arg0, Displayable arg1) {
  87. if (entryScreen.getSelectedIndex() == 0) {
  88. Thread fullScreenThread = new Thread() {
  89. public void run() {
  90. showFullScreenDisplay();
  91. }
  92. };
  93. fullScreenThread.start();
  94. } else {
  95. Thread windowThread = new Thread() {
  96. public void run() {
  97. showDisplayInWindow();
  98. }
  99. };
  100. windowThread.start();
  101. }
  102. }
  103. private Form createBusyForm() {
  104. Form form = new Form("Please wait...");
  105. form.append("Loading movie...");
  106. return form;
  107. }
  108.  
  109. public void playerUpdate(Player player, String event, Object eventData) {
  110. if (event == PlayerListener.END_OF_MEDIA) {
  111. Display.getDisplay(this).setCurrent(entryScreen);
  112. }
  113. }
  114. }
secret