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,
Please see this URL.
There you can get the source code with excellent animation programs and your regarding import also can be found out.
http://www.csse.monash.edu.au/courseware/cse3420/Lectures/Module8/module.html
Thanks
Bakrudeen
It looks like I don't know how to run the application. I put a midi file name "CanYouFeel" to the same directory as the program. Then I type in the command
java MoviePlayer CanYouFeel.mid
but it failed to execute the application. Is it the way I run the program wrong.
Regards
del3