Graphics Reference
In-Depth Information
Figure 6.15
A single triangle rendered in a
CAEAGLLayer
using OpenGL
In a real OpenGL application, we would probably want to call the
-drawFrame
method
60 times per second using an
NSTimer
or
CADisplayLink
(see Chapter 11, “Timer-
Based Animation”), and we would separate out geometry generation from drawing so that
we aren't regenerating our triangle's vertices every frame (and also so that we can draw
something other than a single triangle), but this should be enough to demonstrate the
principle.
The last layer type we will look at is
AVPlayerLayer
. Although not part of the Core
Animation framework (the AV prefix is a bit of a giveaway),
AVPlayerLayer
is an
example of another framework (in this case, AVFoundation) tightly integrating with Core
Animation by providing a
CALayer
subclass to display a custom content type.
AVPlayerLayer
is used for playing video on iOS. It is the underlying implementation
used by high-level APIs such as
MPMoviePlayer
, and provides lower-level control over
the display of video. Usage of
AVPlayerLayer
is actually pretty straightforward: You
can either create a layer with a video player already attached using the
+playerLayerWithPlayer:
method, or you can create the layer first and attach an
AVPlayer
instance using the
player
property.
Before we begin, we need to add the AVFoundation framework to our project, because it's
not included in the default project template. After you've done that, see Listing 6.15 for the
code to create a simple movie player. Figure 6.16 shows the movie player in action.