62,614
社区成员
发帖
与我相关
我的任务
分享
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Component;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
public class PlayDome extends Applet implements ControllerListener {
/**
* Playing an MPEG Movie in an Applet
*/
private static final long serialVersionUID = 1L;
Player player = null;
public static void main(String[] args) {
new PlayDome().init();
}
public void init() {
setLayout(new BorderLayout());
MediaLocator mrl = new MediaLocator(new java.lang.String(
"file:///E:\\XLMMS.wmv"));
try {
player = Manager.createPlayer(mrl);
//System.out.println("test1:" + 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 destroy() {
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();
}
}
}
// For applets, check to see if the media file has a file extension
// If not, throw an IOException with the following message:
// "For security reasons, from an applet, cannot read a media file with no extension"
// If there is a file extension, make sure it is registered in the
// mimetable.
// If not throw an IOException.
if (jmfSecurity != null) {
int i = fileName.lastIndexOf(".");
if (i != -1) {
String ext = fileName.substring(i+1).toLowerCase();
if (!mimeTable.containsKey(ext)) {
// Treat aif as a special case due to bug in IE VM
if (!ext.equalsIgnoreCase("aif"))
throw new IOException("Permission Denied: From an applet cannot read media file with extension " + ext);
}
} else {
throw new IOException("For security reasons, from an applet, cannot read a media file with no extension");
}
}