MPMoviePlayerViewController
An MPMoviePlayerViewController is, as its name implies, a view controller (a UIViewController subclass). It manages an MPMoviePlayerController (its moviePlayer) and automatically provides a fullscreen presentation of the MPMoviePlayerController’s view. Thus, an MPMoviePlayerViewController has some strong advantages of simplicity.
The documentation says that you can use an MPMoviePlayerViewController wherever you would use a UIViewController, such as a child view controller in a tab bar interface or navigation interface, but the MPMoviePlayerViewController’s own interface seems to make the most sense when it is a presented view controller. A category on UIViewController even provides a special method for presenting it, presentMoviePlayerViewControllerAnimated:, which uses a style of animation otherwise unavailable, whereby the current view slides out to reveal the movie view. To remove the view in code, you could then call dismissMoviePlayerViewControllerAnimated. Here’s a simple example:
NSURL* m = [[NSBundle mainBundle] URLForResource:@"ElMirage"
withExtension:@"mp4"];
MPMoviePlayerViewController* mpvc =
[[MPMoviePlayerViewController alloc] initWithContentURL: m];
mpvc.moviePlayer.shouldAutoplay = NO; // optional
[self presentMoviePlayerViewControllerAnimated:mpvc];In that code, I’ve set the MPMoviePlayerViewController’s moviePlayer’s shouldAutoplay property just to show that it can be done; the moviePlayer is an MPMoviePlayerController, and can be sent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access