next up previous
Next: Media AND Presenters Up: Displaying and Streaming Movies Previous: Converting To Full Screen

Using Movie Callbacks

This section explains how to display a QuickTime movie within a window and add callbacks. The callbacks are QuickTime calling back into Java through the movie controller, movie, and QuickTime VR APIs. Callbacks can be used by an application to perform its own tasks when certain conditions occur within QuickTime itself. The callbacks used in the MovieCallbacks program are invoked when some condition having to do with the presentation of a movie is changed:

The QTCallBack, ActionFilter, or DrawingComplete callbacks are invoked through a direct or indirect call of the QuickTime MoviesTask function.

Many of the callback methods in QuickTime in Java are required to execute in place, in that QuickTime requires a result code in order to proceed. These callbacks provide meaningful feedback when their execute() method returns. The subclasses of QTCallBack, however, can execute asynchronously, in which case QuickTime does not require a result code in order to proceed. This is also true of any of the execute() methods with no return value.

The program just prints out details about the callback when it is invoked. The QuickTime API documentation provides examples and discussions on the usage of these.

To set up a movie drawing callback:

static class MovieDrawing implements MovieDrawingComplete {
public short execute (Movie m) {
System.out.println ("drawing:" + m);
return 0;
}
}

To set up an action filter:

static class PMFilter extends ActionFilter {
public boolean execute (MovieController mc, int action) {
System.out.println (mc + "," + "action:" + action);
return false;
}
public boolean execute (MovieController mc, int action, float value) {
System.out.println (mc + "," + "action:" + action + ",value=" + value);
return false;
}
}

The following code sets up callbacks for QuickTime VR content:

Track t = m.getQTVRTrack (1);
if (t != null) {
QTVRInstance vr = new QTVRInstance (t, mc);
vr.setEnteringNodeProc (new EnteringNode(), 0);
vr.setLeavingNodeProc (new LeavingNode(), 0);
vr.setMouseOverHotSpotProc (new HotSpot(), 0);
Interceptor ip = new Interceptor();
vr.installInterceptProc (QTVRConstants.kQTVRSetPanAngleSelector, ip, 0);
vr.installInterceptProc (QTVRConstants.kQTVRSetTiltAngleSelector, ip, 0);
vr.installInterceptProc (QTVRConstants.kQTVRSetFieldOfViewSelector, ip, 0);
vr.installInterceptProc (QTVRConstants.kQTVRSetViewCenterSelector, ip, 0);
vr.installInterceptProc (QTVRConstants.kQTVRTriggerHotSpotSelector, ip, 0);
vr.installInterceptProc (QTVRConstants.kQTVRGetHotSpotTypeSelector, ip, 0);
}
static class EnteringNode implements QTVREnteringNode {
public short execute (QTVRInstance vr, int nodeID) {
System.out.println (vr + ",entering:" + nodeID);
return 0;
}
}
static class LeavingNode implements QTVRLeavingNode {
public short execute (QTVRInstance vr, int fromNodeID, int toNodeID, boolean[]
cancel) {
System.out.println (vr + ",leaving:" + fromNodeID + ",entering:" +
toNodeID);
// cancel[0] = true;
return 0;
}
}
static class HotSpot implements QTVRMouseOverHotSpot {
public short execute (QTVRInstance vr, int hotSpotID, int flags) {
System.out.println (vr + ",hotSpot:" + hotSpotID + ",flags=" + flags);
return 0;
}
}

The following code shows how to install a QTRuntimeException handler:

QTRuntimeException.registerHandler (new Handler());

Runtime exceptions can be thrown by many methods and are thrown where the method does not explicitly declare that it throws an exception. Using the QTRuntimeHandler allows your application to examine the exception and determine if it can be ignored or recovered from. An example of this is the paint() method of a Java component. Its signature is

public void paint (Graphics g);

It is declared not to throw any exceptions. However, the QTDrawable redraw() or setDisplayBounds() calls (which are both invoked on a QTCanvas client) are defined to throw QTExceptions. If the QTCanvas client does throw an exception in this case, it passes it off to a QTRuntimeHandler if the application has registered one, with details about the cause of the exception. The application can then either throw the exception or rectify the situation. If no runtime exception handler is registered, the exception is thrown and caught by the Java VM thread itself.


next up previous
Next: Media AND Presenters Up: Displaying and Streaming Movies Previous: Converting To Full Screen
Dave Marshall
10/4/2001