|
Create an instance of MediaPlayer To create an instance of the MediaPlayer component in a GUI builder environment, you must first import the MediaPlayer Bean to the GUI builder environments, e.g.IBM VisualAge for Java, and then drag the MediaPlayer icon to the free-form surface. To create a MediaPlayer instance in Java code, enter: import javax.media.bean.playerbean.MediaPlayer; MediaPlayer1 = new javax.media.bean.playerbean.MediaPlayer();Set the media file location for MediaPlayer If you are in a GUI builder environments, you can wire the the media file location via the "media location" property of the MediaPlayer. To set the media location property in Java code, use the setMediaLocation method: // Set the media location
MediaPlayer1.setMediaLocation(new java.lang.String("file:///E:/jvideo/media/Sample1.mov"));
You can place this
code in any appropriate method in your applet or application.
For example, place the code in the init method.
Start the instance of the MediaPlayer To start the instance of the MediaPlayer, use the start method: MediaPlayer1.start();You can create a start button in your applet or application to connect to the start method in MediaPlayer Bean, the media file starts playing when you click on the button. Or you can connect the start method to the applet or application directly, so the media file starts when the applet or application starts. Stop the instance of the MediaPlayer To stop the instance of the MediaPlayer, use the stop method: MediaPlayer1.stop();You can create a stop button in your applet or application to connect to the stop method in the MediaPlayer Bean. Tthe media file stops playing when you click on the button. Or you can connect the stop method to the applet or application directly, so the media file stops when the applet or application stops. To see a complete sample program using MediaPlayer see MediaPlayerSample.java
| ||||||||||||||||||||||||||||||||
|
| ||||||||||||