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.

Movie with on-screen controller

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 ...

Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.