- Installing QuickTime for Java
- Learning by Example
- Playing the Movie
- Wrapping Up
- References
Playing the Movie
Once our JComponent is created, displaying the movie is quite simple. The start() method of our instantiated quicktime.std.movies.Movie object starts playing the movie. The beauty of the QuickTime API is that we're abstracted from having to repaint the screen scene by scene. The complexity of displaying the movie is handled behind the scenes (no pun intended), as is the playing of sound that might accompany a movie file. Figure 4 shows the QTJViewer application in action. We played the Sample.mov file that's installed with QuickTime, which serves as a good test because it contains both audio and video.
Figure
4 The QTJViewer playing a movie file.
To stop the movie, we simply use the Movie object's stop() method, followed by the goToBeginning() method, which moves the index back to the beginning of the movie. To pause, we use the stop() method only.
To keep track of where we are in the movie as it's being played, we tap into the Movie object's getTime method, which returns an integer. The progress bar of our sample Swing application is taken care of by an inner class named ProgressThread, which continually updates our javax.swing.JProgressBar Swing component (which we reference with the call getMovieProgress() as long as a movie is playing):
int time = movie.getTime(); getMovieProgress().setValue(time);
Now that you've walked through our sample application, you should feel comfortable enough with the QuickTime for Java API to venture out and create your own applications.