//file: MoviePlayer.java
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;
import javax.media.*;
public class MoviePlayer extends JComponent {
public static void main(String[] args) throws Exception {
final JFrame f = new JFrame("MoviePlayer");
f.addNotify( );
f.setLocation(100, 100);
f.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent we) { System.exit(0); }
});
URL url = new URL(args[0]);
final Player player = Manager.createPlayer(url);
player.realize( );
player.addControllerListener(new ControllerListener( ) {
public void controllerUpdate(ControllerEvent ce) {
if (ce instanceof RealizeCompleteEvent) {
Component c = player.getVisualComponent( );
Container content = f.getContentPane( );
content.setLayout(new BorderLayout( ));
content.add(c, BorderLayout.CENTER);
Insets i = f.getInsets( );
Dimension d = c.getSize( );
f.setSize(d.width + i.left + i.right,
d.height + i.top + i.bottom);
f.setVisible(true);
player.start( );
}
}
});
}
}
|