iPhone Game Development - Chris Craft [48]
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mMoviePlayer];
There are two other notifications available on the MPMoviePlayerController:
The MPMoviePlayerContentPreloadDidFinishNotification event occurs once the movie has been loaded into memory and is ready to play.
The MPMoviePlayerScalingModeDidChangeNotification event occurs if the screen is rotated and so on.
Tip
Consider using MPMoviePlayerContentPreloadDidFinishNotification so you can display a loading screen until the movie player is able to load the movie into memory.
Scaling mode determines how any movie that does not exactly fit the screen will be scaled to fill the screen. We went with MPMovieScalingModeAspectFill because it was okay if the black around the flame went off the screen and got cropped off.
Here are all the valid scaling modes for displaying movies for MPMovieScalingMode:
MPMovieScalingModeNone. Do not scale the movie.
MPMovieScalingModeAspectFit. Scale the movie until one dimension fits on the screen exactly. In the other dimension, the region between the edge of the movie and the edge of the screen is filled with a black bar. The aspect ratio of the movie is preserved.
MPMovieScalingModeAspectFill. Scale the movie until the movie fills the entire screen. Content at the edges of the larger of the two dimensions is clipped so that the other dimension fits the screen exactly. The aspect ratio of the movie is preserved.
MPMovieScalingModeFill. Scale the movie until both dimensions fit the screen exactly. The aspect ratio of the movie is not preserved.
Sometimes it really helps to see the code behind a feature you are working with even if only for reference. So here is the source code for the MPMovieScalingMode:
typedef enum
{
// No scaling applied at all.
MPMovieScalingModeNone,
// Uniform scale until one dimension fits. One dimension may be
// filled with bars the color of the backgroundColor property.
MPMovieScalingModeAspectFit,
// Uniform scale until the movie fills the visible bounds. One
// dimension may have clipped contents.
MPMovieScalingModeAspectFill,
// Non-uniform scale. Both render dimensions will exactly match
// the visible bounds.
MPMovieScalingModeFill
} MPMovieScalingMode;
Caution
Be careful when using the MPMovieScalingModeFill, as it is the only scaling mode that does not preserve the video's aspect ratio. Using this may cause displayed video to appear distorted.
In this case, you will want to use the MPMovieControlModeHidden movie control mode because showing any movie controls will give away the trick to the watcher.
mMoviePlayer.movieControlMode = MPMovieControlModeHidden;
Here is the source code for the MPMovieControlMode enumeration. This should help prove the value of reading through a class's source code to learn more about its inner workings:
typedef enum
{
// Standard controls (e.g. play/pause, volume slider, timeline) are
// visible
MPMovieControlModeDefault,
// Only the volume control is visible
MPMovieControlModeVolumeOnly,
// No controls are visible
MPMovieControlModeHidden
} MPMovieControlMode;
Here are all the valid movie control modes for MPMovieControlMode:
MPMovieControlModeDefault. Display the standard controls for controlling playback. This includes play/pause controls, a volume slider, and a timeline control.
MPMovieControlModeVolumeOnly. Display volume controls only.
MPMovieControlModeHidden. Do not display any controls. This mode prevents the user from controlling playback. Use this mode any time you only want the user to be able to see the video. A virtual aquarium video application, for example, would not appear realistic behind a set of playback controls.
The background is used for any area on the MPMoviePlayerController that is not filled by the video due to choices made for MPMovieScalingMode