Adding a Controller
This
application isn’t
particularly user-friendly yet—the user can’t
start or stop the movie, move through it, or set the volume.
Fortunately, it’s easy to use a
MovieController
to get the standard QuickTime controller
bar, an on-screen control widget that provides a play/pause button, a
volume control, and the movie position control (typically called a
“scrubber” in QuickTime parlance).
How do I do that?
Create a new class in the source file
BasicQTController.java. The main() is exactly the same as before, while the constructor adds
one new line and changes another, as seen in Example 2-2.
Example 2-2. Getting a movie component with a controller
public class BasicQTController extends Frame {
public BasicQTController (Movie m) throws QTException {
super ("Basic QT Controller");
MovieController mc = new MovieController(m);
QTComponent qc = QTFactory.makeQTComponent (mc);
Component c = qc.asComponent( );
add (c);
pack( );
}Note
Compile and run this example with ant run-ch02-basicqtcontroller.
The result, when run, looks like the application in Figure 2-3. Notice the presence of the classic QuickTime control bar at the bottom of the window.

Figure 2-3. Movie with on-screen controller
What just happened?
This time, instead of asking the QTFactory to make
a QTComponent from the Movie,
the program creates a MovieController object from
the Movie and asks the
QTFactory to make ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access