next up previous
Next: Converting To Full Screen Up: Displaying and Streaming Movies Previous: Playing a Streaming Movie

Using The Detached Controller

The code sample in this section shows how to select and then play a QuickTime movie with its controller detached. The media required is a QuickTime movie of the user's choice.

You are prompted to select a movie file. If you make the selection, a window is constructed and the movie and its controller are presented, as shown in Figure 9.3


The Detached Controller

The movie and its controller are displayed separately in the same window, with the controller at the top and the actual movie at the bottom. They are separated by a label. Though the movie and its controller are shown here in the same window, they could also be displayed in different windows, even on different monitors.

You use a QTPlayer object to play the movie in its canvas, and you can use a MoviePlayer object to present the movie.

void setControllerCanvas(Movie mMovie) throws QTException {
QTCanvas controllerCanvas = new QTCanvas();
MovieController mController = new MovieController(mMovie,
mcScaleMovieToFit);
mController.setAttached(false);
QTPlayer qtPlayer = new QTPlayer(mController);
add(controllerCanvas, "North");
controllerCanvas.setClient(qtPlayer, true);
}

You can attach or detach the movie from its controller using this method:

mController.setAttached(false);

Once the controller is a client of its canvas, if the movie is reattached to the controller, you need to notify the canvas of this change in the client's display characteristics.

Now you create the canvas for the detached movie:

void setMovieCanvas(Movie mMovie) throws QTException{
QTCanvas movieCanvas = new QTCanvas();
MoviePlayer mPlayer = new MoviePlayer(mMovie);
add(movieCanvas, "South");
movieCanvas.setClient(mPlayer, true);
}

The following snippet shows the code that assembles the Detached-Controller window. Resizing the window resizes the movie and the width of the controller but not its height.

DetachedController(Movie mMovie) throws QTException {
super ("QT in Java");
setControllerCanvas(mMovie);
setMovieCanvas(mMovie);
add (new Label("DETACHED CONTROLLER"), "Center");
.
.
.
}

The full code listing for the DetachedController.java example can be found in the online code examples.


next up previous
Next: Converting To Full Screen Up: Displaying and Streaming Movies Previous: Playing a Streaming Movie
Dave Marshall
10/4/2001