日期:2014-05-20 浏览次数:20789 次
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();
}
}
}