探讨应用JMF 开发applet 的媒体播放器

浏览:49日期:2023-03-01
内容: 一、jmf 开发环境的设置下载jmf windows performace packhttp://java.sun.com/products/java-media/jmf/2.1.1/setup.html设置路径set JMFHOME=C:JMF2.1.1 set CLASSPATH=%JMFHOME%libjmf.jar;%JMFHOME%libsound.jar;.;%CLASSPATH%二、播放器的例子代码//use media player bean play localhost filesimport 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((comp=player.getVisualComponent())!=null) add('center',comp); if((comp=player.getControlPanelComponent())!=null) add('south',comp); validate(); } } }三、测试网页的写法 四、遗留问题1、很奇怪,javax.media.Player player=null; 这样写,可以编译通过,但是这样写 Player player=null ; 编译就会出错。不知道为什么2、此applet 运行的时候可能会出现java.lang.NoClassDefFoundError错误,以下是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. When you install JMF 2.1.1
相关文章: