A movie player (of type
MPMoviePlayerController) manages the playback of a movie from a file or a network stream. Playback occurs in a view owned by the movie player and takes place either fullscreen or inline. You can incorporate a movie player’s view into a view hierarchy owned by your app, or use an
MPMoviePlayerViewController object to manage the presentation for you.
- iOS 2.0–9.0Deprecated
Movie players (iOS 4.3 and later) support wireless movie playback to AirPlay-enabled hardware such as Apple TV.. Starting in iOS 5.0, AirPlay playback is enabled by default. To disable AirPlay in your app, set the
allowsAirPlay property to
false. In iOS 8.0 and later, users access AirPlay compatible hardware through the Control Panel, no AirPlay control is displayed by the movie player.
When you add a movie player’s view to your app’s view hierarchy, be sure to size the frame correctly, as shown here:
Consider a movie player view to be an opaque structure. You can add your own custom subviews to layer content on top of the movie but you must never modify any of its existing subviews.
In addition to layering content on top of a movie, you can provide custom background content by adding subviews to the view in the
backgroundView property. Custom subviews are supported in both inline and fullscreen playback modes but you must adjust the positions of your views when entering or exiting fullscreen mode. Use the
MPMoviePlayerWillExitFullscreen notifications to detect changes to and from fullscreen mode.
This class supports programmatic control of movie playback, and user-based control via buttons supplied by the movie player. You can control most aspects of playback programmatically using the methods and properties of the
MPMediaPlayback protocol, to which this class conforms. The methods and properties of that protocol let you start and stop playback, seek forward and backward through the movie’s content, and even change the playback rate. In addition, the
controlStyle property of this class lets you display a set of standard system controls that allow the user to manipulate playback. You can also set the
shouldAutoplay property for network-based content to start automatically.
You typically specify the movie you want to play when you create a new
MPMoviePlayerController object. However, you can also change the currently playing movie by changing the value in the
contentURL property. Changing this property lets you reuse the same movie player controller object in multiple places. For performance reasons you may want to play movies as local files. Do this by first downloading them to a local directory.
To facilitate the creation of video bookmarks or chapter links for a long movie, the
MPMoviePlayerController class defines methods for generating thumbnail images at specific times within a movie. You can request a single thumbnail image using the
thumbnailImageAtTime:timeOption: method or request multiple thumbnail images using the
To play a network stream whose URL requires access credentials, first create an appropriate
URLCredential object. Do this by calling, for example, the
init(user:password:persistence:) method, as shown here:
In addition, create an appropriate
URLProtectionSpace object, as shown here. Make appropriate modifications for the realm you are accessing:
With the credential and protection space information in place, you can then play the protected stream.
Movie Player Notifications
A movie player generates notifications to keep your app informed about the state of movie playback. In addition to being notified when playback finishes, your app can be notified in the following situations:
When the movie player begins playing, is paused, or begins seeking forward or backward
When AirPlay playback starts or ends
When the scaling mode of the movie changes
When the movie enters or exits fullscreen mode
When the load state for network-based movies changes
When meta-information about the movie itself becomes available
For more information, see the Notifications section in this document.
This class plays any movie or audio file supported in iOS. This includes both streamed content and fixed-length files. For movie files, this typically means files with the extensions
.3gp and using one of the following compression standards:
H.264 Baseline Profile Level 3.0 video, up to 640 x 480 at 30 fps. (The Baseline profile does not support B frames.)
MPEG-4 Part 2 video (Simple Profile)
If you use this class to play audio files, it displays a white screen with a QuickTime logo while the audio plays. For audio files, this class supports AAC-LC audio at up to 48 kHz, and MP3 (MPEG-1 Audio Layer 3) up to 48 kHz, stereo audio.
Behavior in iOS 4.3 and Earlier
In iOS 4.3 and earlier, a new movie player was automatically prepared to play. Starting in iOS 5.0, in order to facilitate finer-grained playback control, a new movie player is not automatically prepared to play. See the discussion for the
init(contentURL:) instance method.
Behavior in iOS 3.1 and Earlier
In iOS 3.1 and earlier, this class implemented a full-screen movie player only. After creating the movie player and initializing it with a single movie file, you called the
play method to present the movie. (The definition of the
play method has since moved out of this class and into the
MPMediaPlayback protocol.) The movie player object itself handled the actual presentation of the movie content.