站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题探讨应用JMF 开发applet 的媒体播放器

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

摘要: 探讨应用JMF 开发applet 的媒体播放器
内容: 一、jmf 开发环境的设置
下载jmf windows performace pack
http://java.sun.com/products/java-media/jmf/2.1.1/setup.html

设置路径

set JMFHOME=C:\JMF2.1.1
set CLASSPATH=%JMFHOME%\lib\jmf.jar;%JMFHOME%\lib\sound.jar;.;%CLASSPATH%

二、播放器的例子代码

//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((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 /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 一、jmf
↑返回目录
前一篇: 克服J2SE 1.3 ~ 1.4不兼容问题
后一篇: 使用JAVA的串行化打造自己的“对象数据库”