Just as the movie controller API sits below the Control Manager and HIMovieView API, a still lower-level API lets you control the movie directly. You can use these low-level Movie Toolbox calls in addition to, or instead of, a movie controller component.
As a rule, you should not play movies without a movie controller. Most of the operations that act directly on movies can also be performed using a movie controller by calling the MCDoAction function with the appropriate action selector. Do not play movies directly unless you have a compelling reason to do so; use a movie controller instead, or better yet, use a higher-level object that includes a movie controller, such as an HIMovieView.
Important: If you use commands that act directly on a movie that is attached to a controller, be sure to call MCMovieChanged before your next call to MCIdle. This lets the controller know that its internal record of the movie state needs to be updated.
If you play a movie without a movie controller component, your application is responsible for updating the movie, handling all user input, and handling events such as resizing or covering and uncovering the window. Your application starts the movie playing by calling StartMovie, then runs a loop until IsMovieDone returns TRUE. Inside the loop, your application calls MoviesTask and handles any resize, drag, cover/uncover, and UI events. An example of this kind of loop is shown in Listing 1-6.
Listing 6-1 Movie playing loop
#define doTheRightThing 5000 |
void PlayMyMovie (movie, aMovie) |
{ |
WindowPtr aWindow; |
Rect windowRect; |
Rect movieBox; |
Movie aMovie; |
Boolean done = false; |
OSErr err; |
EventRecord theEvent; |
WindowPtr whichWindow; |
short part; |
err = EnterMovies (); |
if (err) return; |
SetRect (&windowRect, 100, 100, 200, 200); |
aWindow = NewCWindow (nil, &windowRect, "\pMovie", |
false, noGrowDocProc, (WindowPtr)-1, |
true, 0); |
GetMovieBox (aMovie, &movieBox); |
OffsetRect (&movieBox, -movieBox.left, -movieBox.top); |
SetMovieBox (aMovie, &movieBox); |
SizeWindow (aWindow, movieBox.right, movieBox.bottom, true); |
ShowWindow (aWindow); |
SetMovieGWorld (aMovie, (CGrafPtr)aWindow, nil); |
StartMovie (aMovie); |
while ( !IsMovieDone(aMovie) ) |
{ |
// Handle resize and update events... |
// Handle drag events |
MoviesTask (aMovie, DoTheRightThing); |
} |
DisposeMovie (aMovie); |
DisposeWindow (aWindow); |
} |
The Movie Toolbox commands for operating directly on movies are listed below. See the documentation on individual functions in QuickTimeAPIReference for more information.
StartMovieStopMovieGoToBeginningOfMovieGoToEndOfMovieMoviesTaskIsMovieDoneUpdateMoviePtInMoviePtInTrackGetMovieStatusGetTrackStatusSetMovieActiveGetMovieActiveSetMovieGWorldGetMovieGWorldSetMovieBoxGetMovieBoxGetMovieDisplayBoundsRgnGetMovieSegmentDisplayBoundsRgnSetMovieDisplayClipRgnGetMovieDisplayClipRgnGetTrackDisplayBoundsRgnGetTrackSegmentDisplayBoundsRgnGetMovieDurationSetMovieTimeValueSetMovieTimeGetMovieTimeSetMovieRateGetMovieRateLast updated: 2005-08-11