Hi,
Here is the sample code for playing the movie.
public class MoviePlayer extends JFrame implements ControllerListener {
private Player player = null;
public static void main(String args[]) {
new MoviePlayer(args[0]);
}
public MoviePlayer(String movieFile) {
getContentPane().setLayout(new BorderLayout());
setSize(new Dimension(200, 200));
setVisible(true);
setTitle(movieFile);
loadMovie(movieFile);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
player.stop();
player.deallocate();
System.exit(1);
}
});
}
private void loadMovie(String movieFile) {
try {
MediaLocator ml = new MediaLocator("file:" + movieFile);
player = Manager.createPlayer(ml);
player.addControllerListener(this);
player.start();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (NoPlayerException npe) {
npe.printStackTrace();
}
}
public synchronized void controllerUpdate(ControllerEvent ce) {
if (ce instanceof RealizeCompleteEvent) {
Component comp;
if ((comp = player.getVisualComponent()) != null)
getContentPane().add(comp, BorderLayout.CENTER);
if ((comp = player.getControlPanelComponent()) != null)
getContentPane().add(comp, BorderLayout.SOUTH);
validate();
}
}
}
I hope this will help you.
Thanks
Bakrudeen
Technical Support Engineer
Sun MicroSystems Inc, India
Hi,
Also you can refer this URL, which gives the excellent examples in Animation.
http://www.csse.monash.edu.au/courseware/cse3420/Lectures/Module8/module.html
I hope this will help you.
Thanks
Bakrudeen
Technical Support Engineer
Sun MicroSystems Inc, India