Cover by Vandad Nahavandipoor

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

9.6. Playing Video Files

Problem

You would like to be able to play video files in your iOS application.

Solution

Use an instance of the MPMoviePlayerController class.

Note

If you simply want to display a full-screen movie player, you can use the MPMoviePlayerViewController class and push your movie player view controller into the stack of view controllers of a navigation controller (for instance), or simply present your movie player view controller as a modal controller on another view controller using the presentMoviePlayerViewControllerAnimated: instance method of UIViewController. In this recipe, we will use MPMoviePlayerController instead of MPMoviePlayerViewController in order to get full access to various settings that a movie player view controller does not offer, such as windowed-mode video playback (not full-screen).

Discussion

The Media Player framework in the iOS SDK allows programmers to play audio and video files, among other interesting things. To be able to play a video file, we will instantiate an object of type MPMoviePlayerController like so:

self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

In this code, moviePlayer is a property of type MPMoviePlayerController defined and synthesized for the current view controller. In older iOS SDKs, programmers had very little control over how movies were played using the Media Player framework. With the introduction of the iPad, the whole framework changed drastically to give more control to programmers and ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required