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 


  4, and the remaining issues 

  1, very strange, javax.media.Player player = null; this writing, can be compiled, but to write Player player = null; compiler will be wrong.    Do not know why 
  2, the applet running time may be java.lang.NoClassDefFoundError wrong, the following is the solution to sun 
  Q: What is this error? 
  Java.lang.NoClassDefFoundError: javax / media / ControllerListener 

  This happens in two situations: 

  Jmf.jar is not in your CLASSPATH 
  Jmf.jar is in your CLASSPATH but you are using the JDK 1.2 + appletviewer. 
  JDK 1.2 and later require standard extensions to be loaded from    / Jre / lib / ext directory. 2.1.1 When you install JMF    / Jre / lib / ext directory 

  3, Q: Why don't JMF applets work in my browser? 

  Possible reasons are: 

  JMF is not properly installed on your machine or is not available on the website that contains the applet in question. Run the JMF diagnostics applet to see if JMF is installed properly: http://java.sun.com/products/java-media / jmf/2.1.1/jmfdiagnostics.html 
  Your browser does not have a JDK 1.1.x compatible Java VM. Upgrade to a more recent version of the browser. 
  The applet might have thrown a security exception - check the Java Console pertaining to your browser. 
  Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd a jmf 
  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply