Graphics Reference
In-Depth Information
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/QTKit.framework if you have
the developer tools installed. (Change that path to use MacOSX10.5.sdk if you use
Leopard rather than Snow Leopard.)
If all you want to do is play a movie, you simply implement playback on load in the
-awakeFromNib method in the AppDelegate using the code in Listing 7-1.
LISTING 7-1 Implementing Simple Movie Playback
- ( void )awakeFromNib;
{
[[window contentView ] setWantsLayer: YES ];
NSString *moviePath = [[ NSBundle mainBundle ]
pathForResource : @”stirfry” ofType : @”mov” ];
movie = [QTMovie movieWithFile:moviePath error: nil ];
if ( movie )
{
QTMovieLayer *layer = [QTMovieLayer layerWithMovie:movie];
[layer setFrame :NSRectToCGRect([[window contentView ] bounds ])];
[[[window contentView ] layer ] addSublayer :layer];
[movie play];
}
}
The code begins by informing the contentView the window that it should be layer-
backed with -setWantsLayer . Next the code instantiates a QTMovie object from a movie
contained in the main bundle. If the movie is valid, we then initialize a QTMovieLayer
with it. Next, the code sets the layer's frame to the content view's bounds and adds the
layer as a sublayer of the content view. It then starts movie playback. That's it. That's all
you need to display a movie in a QTMovieLayer . That being said, it won't be a very func-
tional player if we don't give it some way to control playback.
Adding Basic Playback Controls
Now that we have the basic movie layer
created, the next thing we need to do is
add some controls to the view so we can
play, pause, and go back or forward in the
movie. In Interface Builder, add a button
to start and stop playback along with two
additional buttons: one to advance the
frame and one to go back one frame.
NOTE
Note on Sample Code
The sample code in the project called Movie
Player with Overlay is complete and shows
all the changes we discuss in this section. In
other words, all the actions are already
connected in Interface Builder for you, and
the code reflects only the final state and not
the intermediate code we mention.
 
Search WWH ::




Custom Search