Application JMF applet development of the media player
Abstract: To explore the development of JMF applet media player
Contents: I. jmf development environment settings download jmf windows performace pack
Http://java.sun.com/products/java-media/jmf/2.1.1/setup.html
Set path
Set JMFHOME = C: \ JMF2.1.1
JMFHOME set CLASSPATH =%% \ lib \ jmf.jar;% JMFHOME% \ lib \ sound.jar;.; CLASSPATH%%
Second, the player's code examples
/ / Use media player bean play localhost files
Import java.applet .*;
Import java.awt .*;
Import java.net .*;
Import javax.media .*;
Public class PlayerApplet extends Applet implements ControllerListener
(
Javax.media.Player player = null;
Public void init () (
SetLayout (new BorderLayout ());
/ / 1. Get the FILE parameter.
String mediaFile = getParameter ( "FILE");
Try (
/ / 2. Create a URL from the FILE parameter. The URL
/ / Class is defined in java.net.
URL mediaURL = new URL (getDocumentBase (), mediaFile);
/ / 3. Create a player with the URL object.
Player = Manager.createPlayer (mediaURL);
/ / 4. Add PlayerApplet as a listener on the new player.
Player.addControllerListener (this);
)
Catch (Exception e) (
System.err.println ( "Got exception" + e);
)
)
Public void start ()
(
Player.start ();
)
Public void stop ()
(
Player.stop ();
Player.deallocate ();
)
Public void destory ()
(
Player.close ();
)
Public synchronized void controllerUpdate (ControllerEvent event)
(
If (event instanceof RealizeCompleteEvent)
(
Component comp;
If ((player.getVisualComponent ())!= comp = null)
Add (the "center" comp);
If ((player.getControlPanelComponent ())!= comp = null)
Add (the "south", comp);
Validate ();
)
)
)
Third, the writing test page