MPMoviePlayerController
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.
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 NOfalse. 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:
MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: myURL];[player prepareToPlay];[player.view setFrame: myView.bounds]; // player's frame must match parent's[myView addSubview: player.view];// ...[player play];
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 MPMoviePlayerWillEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification 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 requestThumbnailImagesAtTimes:timeOption: method.
To play a network stream whose URL requires access credentials, first create an appropriate NSURLCredential object. Do this by calling, for example, the initWithUser:password:persistence: method, as shown here:
NSURLCredential *credential = [[NSURLCredential alloc]initWithUser: @"userName"password: @"password"persistence: NSURLCredentialPersistenceForSession];self.credential = credential;[credential release];
In addition, create an appropriate NSURLProtectionSpace object, as shown here. Make appropriate modifications for the realm you are accessing:
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]initWithHost: "@streams.mydomain.com"port: 80protocol: @"http"realm: @"mydomain.com"authenticationMethod: NSURLAuthenticationMethodDefault];self.protectionSpace = protectionSpace;[protectionSpace release];
Add the URL credential and the protection space to the Singleton NSURLCredentialStorage object. Do this by calling, for example, the setCredential:forProtectionSpace: method, as shown here:
[[NSURLCredentialStorage sharedCredentialStorage]setDefaultCredential: credentialforProtectionSpace: protectionSpace];
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.
Supported Formats
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 .mov, .mp4, .mpv, and .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 initWithContentURL: instance method.
Also, AirPlay was disabled by default in iOS 4.3 and earlier. Starting in iOS 5.0, the default for the allowsAirPlay property is YEStrue.
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.
-
Returns a
MPMoviePlayerControllerobject initialized with the movie at the specified URL.Declaration
Swift
init!(contentURLurl: NSURL!)Objective-C
- (instancetype)initWithContentURL:(NSURL *)urlParameters
urlThe location of the movie file. This file must be located either in your app directory or on a remote server.
Return Value
The movie player object.
Discussion
This method initializes a movie player, but does not prepare it for playback. To prepare a new movie player for playback, call the
prepareToPlaymethod, described in MPMediaPlayback Protocol Reference.To be notified when a new movie player is ready to play, register for the
MPMoviePlayerLoadStateDidChangeNotificationnotification. You can then check load state by accessing theloadStateproperty.To check for errors in URL loading, register for the
MPMoviePlayerPlaybackDidFinishNotificationnotification. On error, this notification contains anNSErrorobject available using the@"error"key in the notification’suserInfodictionary.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
The URL that points to the movie file.
Declaration
Swift
@NSCopying var contentURL: NSURL!Objective-C
@property(nonatomic, copy) NSURL *contentURLDiscussion
If you set this property while a movie is playing, that movie pauses and the new movie begins loading. The new movie starts playing at the beginning.
Availability
Available in iOS 4.3 and later.
Deprecated in iOS 9.0.
-
The playback type of the movie.
Declaration
Swift
var movieSourceType: MPMovieSourceTypeObjective-C
@property(nonatomic) MPMovieSourceType movieSourceTypeDiscussion
The default value of this property is
MPMovieSourceTypeUnknown. This property provides a clue to the playback system as to how it should download and buffer the movie content. If you know the source type of the movie, setting the value of this property before playback begins can improve the load times for the movie content. If you do not set the source type explicitly before playback, the movie player controller must gather this information, which might delay playback.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
The types of media available in the movie. (read-only)
Declaration
Swift
var movieMediaTypes: MPMovieMediaTypeMask { get }Objective-C
@property(nonatomic, readonly) MPMovieMediaTypeMask movieMediaTypesDiscussion
Movies can contain a combination of audio, video, or a combination of the two. The default value of this property is
MPMovieMediaTypeMaskNone. See the MPMovieMediaTypeMask enumeration for possible values of this property.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
Specifies whether the movie player allows AirPlay movie playback.
Discussion
A movie player supports wireless movie playback to AirPlay-enabled hardware. When enabled, the user can select AirPlay-enabled hardware in the Control Panel when such hardware is in range.
The default value is
YEStrue. To disable AirPlay movie playback, set this property’s value toNOfalse.Availability
Available in iOS 4.3 and later.
Deprecated in iOS 9.0.
-
Indicates whether the movie player is currently playing video via AirPlay.
Declaration
Swift
var airPlayVideoActive: Bool { get }Objective-C
@property(nonatomic, readonly, getter=isAirPlayVideoActive) BOOL airPlayVideoActiveDiscussion
You can query this property after receiving an
MPMoviePlayerIsAirPlayVideoActiveDidChangeNotificationnotification to find out whether the AirPlay video started or stopped.Availability
Available in iOS 5.0 and later.
Deprecated in iOS 9.0.
-
The width and height of the movie frame. (read-only)
Declaration
Swift
var naturalSize: CGSize { get }Objective-C
@property(nonatomic, readonly) CGSize naturalSizeDiscussion
This property reports the clean aperture of the video in square pixels. Thus, the reported dimensions take into account anamorphic content and aperture modes.
It is possible for the natural size of a movie to change during playback. This typically happens when the bit-rate of streaming content changes or when playback toggles between audio-only and a combination of audio and video.
Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
A Boolean that indicates whether the movie player is in full-screen mode.
Declaration
Swift
var fullscreen: BoolObjective-C
@property(nonatomic, getter=isFullscreen) BOOL fullscreenDiscussion
The default value of this property is
NOfalse. Changing the value of this property causes the movie player to enter or exit full-screen mode immediately. If you want to animate the transition to full-screen mode, use thesetFullscreen:animated:method instead.Whenever the movie player enters or exits full-screen mode, it posts appropriate notifications to reflect the change. For example, upon entering full-screen mode, it posts
MPMoviePlayerWillEnterFullscreenNotificationandMPMoviePlayerDidEnterFullscreenNotificationnotifications. Upon exiting from full-screen mode, it postsMPMoviePlayerWillExitFullscreenNotificationandMPMoviePlayerDidExitFullscreenNotificationnotifications.The value of this property may also change as a result of the user interacting with the movie player controls.
Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
See Also
-
Causes the movie player to enter or exit full-screen mode.
Declaration
Objective-C
- (void)setFullscreen:(BOOL)fullscreenanimated:(BOOL)animatedParameters
fullscreenSpecify
YEStrueto enter full-screen mode orNOfalseto exit full-screen mode.animatedSpecify
YEStrueto animate the transition between modes orNOfalseto switch immediately to the new mode.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
See Also
-
The scaling mode to use when displaying the movie.
Declaration
Swift
var scalingMode: MPMovieScalingModeObjective-C
@property(nonatomic) MPMovieScalingMode scalingModeDiscussion
Changing this property while the movie player is visible causes the current movie to animate to the new scaling mode.
The default value of this property is
MPMovieScalingModeAspectFit. For a list of available scaling modes, see MPMovieScalingMode.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
The style of the playback controls.
Declaration
Swift
var controlStyle: MPMovieControlStyleObjective-C
@property(nonatomic) MPMovieControlStyle controlStyleDiscussion
The default value of this property is
MPMovieControlStyleDefault. You can change the value of this property to change the style of the controls or to hide the controls altogether. For a list of available control styles, see MPMovieControlStyle.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
A Boolean value that indicates whether the movie player should use the app’s audio session.
Deprecation Statement
There is not replacement for this property and its use is discouraged.
Declaration
Objective-C
@property(nonatomic) BOOL useApplicationAudioSessionDiscussion
The default value of this property is
YEStrue. Setting this property toNOfalsecauses the movie player to use a system-supplied audio session with a non-mixable playback category.When this property is
YEStrue, the movie player shares the app’s audio session. This give you control over how the movie player content interacts with your audio and with audio from other apps, such as the iPod. For important guidance on using this feature, see Working with Movies and iPod Music in Audio Session Programming Guide.Changing the value of this property does not affect the currently playing movie. For the new setting to take effect, you must stop playback and then start it again.
Special Considerations
In iOS 3.1 and earlier, a movie player always uses a system-supplied audio session. To obtain that same behavior in iOS 3.2 and newer, you must set this property’s value to
NOfalse.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 6.0.
-
The duration of the movie, measured in seconds. (read-only)
Declaration
Swift
var duration: NSTimeInterval { get }Objective-C
@property(nonatomic, readonly) NSTimeInterval durationDiscussion
If the duration of the movie is not known, the value in this property is
0.0. If the duration is subsequently determined, this property is updated and aMPMovieDurationAvailableNotificationnotification is posted.Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
The amount of currently playable content. (read-only)
Declaration
Swift
var playableDuration: NSTimeInterval { get }Objective-C
@property(nonatomic, readonly) NSTimeInterval playableDurationDiscussion
For progressively downloaded network content, this property reflects the amount of content that can be played now.
Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
The view containing the movie content and controls. (read-only)
Discussion
This property contains the view used for presenting the video content. This view incorporates all the background, content, and controls needed to display movies. You can incorporate this view into your own view hierarchies or present it by itself using a view controller.
To embed the view into your own view hierarchies, add it as a subview to one of your existing views. A good place to do this is in the
loadVieworviewDidLoadmethod of the custom view controller that presents your view hierarchy. You are free to change the view’sframerectangle to accommodate the space available in your view hierarchy. The movie player uses the value in thescalingModeproperty to scale the movie content to match the frame you specify.If you want to present the view by itself—that is, without embedding it in an existing view hierarchy—you can use an instance of the
MPMoviePlayerViewControllerclass to manage the presentation of the view. That class works directly with the movie player controller to present the view by itself.You can add subviews to the view in this property. You might do this in cases where you want to display custom playback controls or add other custom content that is relevant to your app.
Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
See Also
-
A customizable view that is displayed behind the movie content. (read-only)
Declaration
Swift
var backgroundView: UIView! { get }Objective-C
@property(nonatomic, readonly) UIView *backgroundViewDiscussion
This view provides the backing content, on top of which the movie content is displayed. You can add subviews to the background view if you want to display custom background content.
This view is part of the view hierarchy returned by the
viewproperty.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
See also the methods of the MPMediaPlayback protocol.
-
The network load state of the movie player. (read-only)
Declaration
Swift
var loadState: MPMovieLoadState { get }Objective-C
@property(nonatomic, readonly) MPMovieLoadState loadStateDiscussion
See the MPMovieLoadState enumeration for possible values of this property. To be notified of changes to the load state of a movie player, register for the
MPMoviePlayerLoadStateDidChangeNotificationnotification.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
The current playback state of the movie player. (read-only)
Declaration
Swift
var playbackState: MPMoviePlaybackState { get }Objective-C
@property(nonatomic, readonly) MPMoviePlaybackState playbackStateDiscussion
The playback state is affected by programmatic calls to play, pause, or stop the movie player. It can also be affected by user interactions or by the network, in cases where streaming content cannot be buffered fast enough.
See the
“MPMoviePlaybackState”enumeration for possible values of this property. To be notified of changes to the playback state of a movie player, register for theMPMoviePlayerPlaybackStateDidChangeNotificationnotification.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
The time, specified in seconds within the video timeline, when playback should start.
Declaration
Swift
var initialPlaybackTime: NSTimeIntervalObjective-C
@property(nonatomic) NSTimeInterval initialPlaybackTimeDiscussion
For progressively downloaded content, playback starts at the closest key frame prior to the provided time. For video-on-demand content, playback starts at the nearest segment boundary to the provided time. For live video streams, the playback start time is measured from the start of the current playlist and is rounded to the nearest segment boundary.
The default value of this property is -1, which indicates the natural start time of the movie.
Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
The end time (measured in seconds) for playback of the movie.
Declaration
Swift
var endPlaybackTime: NSTimeIntervalObjective-C
@property(nonatomic) NSTimeInterval endPlaybackTimeDiscussion
The default value of this property is -1, which indicates the natural end time of the movie. This property is not applicable for streamed content.
Availability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
A Boolean that indicates whether a movie should begin playback automatically.
Discussion
The default value of this property is
YEStrue. This property determines whether the playback of network-based content begins automatically when there is enough buffered data to ensure uninterrupted playback.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
A Boolean that indicates whether the first video frame of the movie is ready to be displayed.
Declaration
Swift
var readyForDisplay: Bool { get }Objective-C
@property(nonatomic, readonly) BOOL readyForDisplayDiscussion
The default value of this property is
NOfalse. This property returnsYEStrueif the first video frame is ready to be displayed and returnsNOfalseif there are no video tracks associated. When the value of this property changes toYEStrue, aMPMoviePlayerReadyForDisplayDidChangeNotificationis sent.Availability
Available in iOS 6.0 and later.
Deprecated in iOS 9.0.
-
Determines how the movie player repeats the playback of the movie.
Declaration
Swift
var repeatMode: MPMovieRepeatModeObjective-C
@property(nonatomic) MPMovieRepeatMode repeatModeDiscussion
The default value of this property is
MPMovieRepeatModeNone. For a list of available repeat modes, see MPMovieRepeatMode.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
timedMetadata - timedMetadata(iOS 9.0)Obtains the most recent time-based metadata provided by the streamed movie.
Declaration
Swift
var timedMetadata: [AnyObject]! { get }Objective-C
@property(nonatomic, readonly) NSArray *timedMetadataReturn Value
An array of the most recent
MPTimedMetadataobjects provided by the streamed movie.Availability
Available in iOS 4.0 and later.
Deprecated in iOS 9.0.
-
Requests a video ad to be played.
Declaration
Objective-C
- (void)playPrerollAdWithCompletionHandler:(void (^)(NSError *error))completionHandlerParameters
completionHandlerThe block to be invoked after the system has played or failed to play a pre-roll ad. The
errorargument will be non-nil if a pre-roll ad could not be played.Errors can occur for a number of reasons, such as lack of ad inventory, exceeding the maximum pre-roll ad playback frequency, iAd account configuration issues, and media playback issues. See
ADErrorfor a complete list of possible errors.Discussion
The iAdPreroll category adds support for pre-roll video ads to
MPMoviePlayerControllerobjects.This method is used to request the playing of a pre-roll video ad. The movie player controller must not be playing or configured to autoplay when this method is called. If the movie player controller starts regular playback while a pre-roll ad is playing, the ad stops playing immediately and the main content of the movie player controller is played.
To implement a movie player controller, configure its content and request a pre-roll ad. The completion handler then starts normal playback on the movie player controller, responding to any error conditions in the pre-roll ad first.
Special Considerations
This method is implemented in
iAd.framework.Import Statement
Objective-C
@import iAd;Swift
import iAdAvailability
Available in iOS 7.0 and later.
-
- thumbnailImageAtTime:timeOption:(iOS 7.0)Captures and returns a thumbnail image from the current movie.
Declaration
Objective-C
- (UIImage *)thumbnailImageAtTime:(NSTimeInterval)playbackTimetimeOption:(MPMovieTimeOption)optionParameters
playbackTimeThe time at which to capture the thumbnail image. The time value represents the number of seconds from the beginning of the current movie.
optionThe option to use when determining which specific frame to use for the thumbnail image. For a list of possible values, see MPMovieTimeOption.
Return Value
An image object containing the image from the movie or
nilif the thumbnail could not be captured.Discussion
This method captures the thumbnail image synchronously from the current movie (which is accessible from the
MPMovieSourceTypeUnknownproperty).Availability
Available in iOS 3.2 and later.
Deprecated in iOS 7.0.
-
Captures one or more thumbnail images asynchronously from the current movie.
Declaration
Swift
func requestThumbnailImagesAtTimes(_playbackTimes: [AnyObject]!, timeOptionoption: MPMovieTimeOption)Objective-C
- (void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimestimeOption:(MPMovieTimeOption)optionParameters
playbackTimesAn array of
NSNumberobjects containing the times at which to capture the thumbnail images. Each time value represents the number of seconds from the beginning of the current movie.optionThe option to use when determining which specific frame to use for each thumbnail image. For a list of possible values, see MPMovieTimeOption.
Discussion
This method processes each thumbnail request separately and asynchronously. When the results for a single image arrive, the movie player posts a
MPMoviePlayerThumbnailImageRequestDidFinishNotificationnotification with the results for that image. Notifications are posted regardless of whether the image capture was successful or failed. You should register for this notification prior to calling this method.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Cancels all pending asynchronous thumbnail image requests.
Declaration
Swift
func cancelAllThumbnailImageRequests()Objective-C
- (void)cancelAllThumbnailImageRequestsDiscussion
This method cancels only requests made using the
requestThumbnailImagesAtTimes:timeOption:method. It does not cancel requests made synchronously using thethumbnailImageAtTime:timeOption:method.Availability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
A snapshot of the network playback log for the movie player if it is playing a network stream.
Declaration
Swift
var accessLog: MPMovieAccessLog! { get }Objective-C
@property(nonatomic, readonly) MPMovieAccessLog *accessLogDiscussion
Can be
nil. For information about movie access logs, refer to MPMovieAccessLog Class Reference.Availability
Available in iOS 4.3 and later.
Deprecated in iOS 9.0.
-
A snapshot of the playback failure error log for the movie player if it is playing a network stream.
Declaration
Swift
var errorLog: MPMovieErrorLog! { get }Objective-C
@property(nonatomic, readonly) MPMovieErrorLog *errorLogDiscussion
Can be
nil. For information about movie error logs, refer to MPMovieErrorLog Class Reference.Availability
Available in iOS 4.3 and later.
Deprecated in iOS 9.0.
The following methods and properties are no longer available as of iOS 3.2 and must not be used.
-
The color of the background area behind the movie.
Deprecation Statement
Get the view from the
backgroundViewproperty and set its color directly.Declaration
Objective-C
- (UIColor *)backgroundColorDiscussion
You should avoid using this property. It is available only when you use the
initWithContentURL:method to initialize the movie player controller object.The receiver fades to and from the background color when transitioning to and from playback. Whenever the movie does not fill the screen exactly, this color is used to fill the area between the movie’s frame and the edges of the screen.
The default color for this property is black. You can change this to other colors (including clear) to provide a more appropriate transition from your app’s content to the movie content.
Availability
Available in iOS 2.0 through iOS 7.1.
Deprecated in iOS 3.2.
-
The user controls to display.
Deprecation Statement
Use the
controlStyleproperty instead.Declaration
Objective-C
- (MPMovieControlMode)movieControlModeDiscussion
Avoid using this property. It is available only when you use the
initWithContentURL:method to initialize the movie player controller object.Determines the control (if any) the user has over movie playback. Different modes give the user access to different sets of playback controls, some of which allow the user to pause and resume playback and some of which do not.
This property is set to
MPMovieControlModeDefaultby default. See the MPMovieControlMode enumeration for the available control modes.Availability
Available in iOS 2.0 through iOS 7.1.
Deprecated in iOS 3.2.
-
Constants describing the network load state of the movie player.
Declaration
Swift
struct MPMovieLoadState : OptionSetType { init(rawValuerawValue: UInt) static var Unknown: MPMovieLoadState { get } static var Playable: MPMovieLoadState { get } static var PlaythroughOK: MPMovieLoadState { get } static var Stalled: MPMovieLoadState { get } }Objective-C
enum { MPMovieLoadStateUnknown = 0, MPMovieLoadStatePlayable = 1 << 0, MPMovieLoadStatePlaythroughOK = 1 << 1, MPMovieLoadStateStalled = 1 << 2, }; typedef NSInteger MPMovieLoadState;Constants
-
UnknownMPMovieLoadStateUnknownThe load state is not known.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
PlayableMPMovieLoadStatePlayableThe buffer has enough data that playback can begin, but it may run out of data before playback finishes.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
PlaythroughOKMPMovieLoadStatePlaythroughOKEnough data has been buffered for playback to continue uninterrupted.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
StalledMPMovieLoadStateStalledThe buffering of data has stalled. If started now, playback may pause automatically if the player runs out of buffered data.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
-
-
Constants describing the style of the playback controls.
Declaration
Swift
enum MPMovieControlStyle : Int { case None case Embedded case Fullscreen static var Default: MPMovieControlStyle { get } }Objective-C
enum { MPMovieControlStyleNone, MPMovieControlStyleEmbedded, MPMovieControlStyleFullscreen, MPMovieControlStyleDefault = MPMovieControlStyleFullscreen }; typedef NSInteger MPMovieControlStyle;Constants
-
NoneMPMovieControlStyleNoneNo controls are displayed.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
EmbeddedMPMovieControlStyleEmbeddedControls for an embedded view are displayed. The controls include a start/pause button, a scrubber bar, and a button for toggling between fullscreen and embedded display modes.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
FullscreenMPMovieControlStyleFullscreenControls for fullscreen playback are displayed. The controls include a start/pause button, a scrubber bar, forward and reverse seeking buttons, a button for toggling between fullscreen and embedded display modes, a button for toggling the aspect fill mode, and a Done button. Tapping the done button pauses the video and exits fullscreen mode.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
DefaultMPMovieControlStyleDefaultFullscreen controls are displayed by default.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
-
-
Constants describing the reason that playback ended.
Declaration
Swift
enum MPMovieFinishReason : Int { case PlaybackEnded case PlaybackError case UserExited }Objective-C
enum { MPMovieFinishReasonPlaybackEnded, MPMovieFinishReasonPlaybackError, MPMovieFinishReasonUserExited }; typedef NSInteger MPMovieFinishReason;Constants
-
PlaybackEndedMPMovieFinishReasonPlaybackEndedThe end of the movie was reached.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
PlaybackErrorMPMovieFinishReasonPlaybackErrorThere was an error during playback.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
UserExitedMPMovieFinishReasonUserExitedThe user stopped playback.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
-
-
Constants describing the current playback state of the movie player.
Declaration
Swift
enum MPMoviePlaybackState : Int { case Stopped case Playing case Paused case Interrupted case SeekingForward case SeekingBackward }Objective-C
enum { MPMoviePlaybackStateStopped, MPMoviePlaybackStatePlaying, MPMoviePlaybackStatePaused, MPMoviePlaybackStateInterrupted, MPMoviePlaybackStateSeekingForward, MPMoviePlaybackStateSeekingBackward }; typedef NSInteger MPMoviePlaybackState;Constants
-
StoppedMPMoviePlaybackStateStoppedPlayback is currently stopped. Playback will commence from the beginning of the movie.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
PlayingMPMoviePlaybackStatePlayingPlayback is currently under way.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
PausedMPMoviePlaybackStatePausedPlayback is currently paused. Playback will resume from the point where it was paused.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
InterruptedMPMoviePlaybackStateInterruptedPlayback is temporarily interrupted, perhaps because the buffer ran out of content.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
SeekingForwardMPMoviePlaybackStateSeekingForwardThe movie player is currently seeking towards the end of the movie.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
SeekingBackwardMPMoviePlaybackStateSeekingBackwardThe movie player is currently seeking towards the beginning of the movie.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
-
-
Constants describing how the movie player repeats content at the end of playback.
Declaration
Swift
enum MPMovieRepeatMode : Int { case None case One }Objective-C
enum { MPMovieRepeatModeNone, MPMovieRepeatModeOne }; typedef NSInteger MPMovieRepeatMode;Constants
-
NoneMPMovieRepeatModeNoneContent is not repeated when playback finishes
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
OneMPMovieRepeatModeOneThe current movie is repeated when it finishes.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
-
-
Constants describing how the movie content is scaled to fit the frame of its view.
Declaration
Swift
enum MPMovieScalingMode : Int { case None case AspectFit case AspectFill case Fill }Objective-C
typedef enum { MPMovieScalingModeNone, MPMovieScalingModeAspectFit, MPMovieScalingModeAspectFill, MPMovieScalingModeFill } MPMovieScalingMode;Constants
-
NoneMPMovieScalingModeNoneDo not scale the movie.
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
AspectFitMPMovieScalingModeAspectFitScale the movie uniformly until one dimension fits the visible bounds of the view exactly. In the other dimension, the region between the edge of the movie and the edge of the view is filled with a black bar. The aspect ratio of the movie is preserved.
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
AspectFillMPMovieScalingModeAspectFillScale the movie uniformly until the movie fills the visible bounds of the view. Content at the edges of the larger of the two dimensions is clipped so that the other dimension fits the view exactly. The aspect ratio of the movie is preserved.
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
FillMPMovieScalingModeFillScale the movie until both dimensions fit the visible bounds of the view exactly. The aspect ratio of the movie is not preserved.
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 2.0 and later.
-
-
Constants describing which frame to use when generating thumbnail images.
Declaration
Swift
enum MPMovieTimeOption : Int { case NearestKeyFrame case Exact }Objective-C
enum { MPMovieTimeOptionNearestKeyFrame, MPMovieTimeOptionExact }; typedef NSInteger MPMovieTimeOption;Constants
-
NearestKeyFrameMPMovieTimeOptionNearestKeyFrameGenerate a thumbnail image using the nearest key frame. This frame could be several frames away from the current frame. This option generally offers better performance than trying to find the exact frame.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
ExactMPMovieTimeOptionExactUse the exact current frame.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
-
-
Specifies the types of content available in the movie file.
Declaration
Swift
struct MPMovieMediaTypeMask : OptionSetType { init(rawValuerawValue: UInt) static var None: MPMovieMediaTypeMask { get } static var Video: MPMovieMediaTypeMask { get } static var Audio: MPMovieMediaTypeMask { get } }Objective-C
enum { MPMovieMediaTypeMaskNone = 0, MPMovieMediaTypeMaskVideo = 1 << 0, MPMovieMediaTypeMaskAudio = 1 << 1 }; typedef NSInteger MPMovieMediaTypeMask;Constants
-
NoneMPMovieMediaTypeMaskNoneThe types of media available in the media are not yet known.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
VideoMPMovieMediaTypeMaskVideoThe movie file contains video media.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
AudioMPMovieMediaTypeMaskAudioThe movie file contains audio media.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
Discussion
You can OR the specified constants together to specify a movie
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
-
-
Specifies the type of the movie file.
Declaration
Swift
enum MPMovieSourceType : Int { case Unknown case File case Streaming }Objective-C
enum { MPMovieSourceTypeUnknown, MPMovieSourceTypeFile, MPMovieSourceTypeStreaming }; typedef NSInteger MPMovieSourceType;Constants
-
UnknownMPMovieSourceTypeUnknownThe movie type is not yet known.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
FileMPMovieSourceTypeFileThe movie is a local file or is a file that can be downloaded from the network.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
StreamingMPMovieSourceTypeStreamingThe movie is a live or on-demand stream.
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
Import Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
-
-
The following keys may be found in the
userInfodictionary of aMPMoviePlayerThumbnailImageRequestDidFinishNotificationnotification.Declaration
Swift
let MPMoviePlayerThumbnailImageKey: String let MPMoviePlayerThumbnailTimeKey: String let MPMoviePlayerThumbnailErrorKey: StringObjective-C
NSString *const MPMoviePlayerThumbnailImageKey; NSString *const MPMoviePlayerThumbnailTimeKey; NSString *const MPMoviePlayerThumbnailErrorKey;Constants
-
MPMoviePlayerThumbnailImageKeyMPMoviePlayerThumbnailImageKeyThe value of this key is a
UIImageobject containing the image that was obtained for the desired frame.Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
MPMoviePlayerThumbnailTimeKeyMPMoviePlayerThumbnailTimeKeyThe value of this key is a
NSNumberobject containing a double value. This value represents the actual time (measured in seconds) from the beginning of the movie at which the image was captured.Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
MPMoviePlayerThumbnailErrorKeyMPMoviePlayerThumbnailErrorKeyThe value of this key is an
NSErrorobject identifying the error that occurred, if any.Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
-
The following keys may be found in the
userInfodictionary of notifications for transitioning in or out of full-screen mode.Declaration
Swift
let MPMoviePlayerFullscreenAnimationDurationUserInfoKey: String let MPMoviePlayerFullscreenAnimationCurveUserInfoKey: StringObjective-C
NSString *const MPMoviePlayerFullscreenAnimationDurationUserInfoKey; NSString *const MPMoviePlayerFullscreenAnimationCurveUserInfoKey;Constants
-
MPMoviePlayerFullscreenAnimationDurationUserInfoKeyMPMoviePlayerFullscreenAnimationDurationUserInfoKeyThe value of this key is an
NSNumbercontaining a double value. This value represents the duration (measured in seconds) of the animation used to transition in or out of full-screen mode.Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
MPMoviePlayerFullscreenAnimationCurveUserInfoKeyMPMoviePlayerFullscreenAnimationCurveUserInfoKeyThe value of this key is an
NSNumbercontaining an integer value that represents one of theUIViewAnimationCurveconstants.Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
-
The following key may be found in the userInfo dictionary of a
MPMoviePlayerPlaybackDidFinishNotificationnotification.Declaration
Swift
let MPMoviePlayerPlaybackDidFinishReasonUserInfoKey: StringObjective-C
NSString *const MPMoviePlayerPlaybackDidFinishReasonUserInfoKey;Constants
-
MPMoviePlayerPlaybackDidFinishReasonUserInfoKeyMPMoviePlayerPlaybackDidFinishReasonUserInfoKeyThe value of this key is an
NSNumbercontaining an integer value that represents one of the“MPMovieFinishReason”constants.Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
-
Options for displaying movie playback controls.
Use the
“MPMovieControlStyle”constants in conjunction with thecontrolStyleproperty instead.Declaration
Objective-C
typedef enum { MPMovieControlModeDefault, MPMovieControlModeVolumeOnly, MPMovieControlModeHidden } MPMovieControlMode;Constants
-
MPMovieControlModeDefaultDisplay the standard controls for controlling playback. This includes play/pause controls, a volume slider, and a timeline control.
Available in iOS 2.0 through iOS 7.1.
-
MPMovieControlModeVolumeOnlyDisplay volume controls only.
Available in iOS 2.0 through iOS 7.1.
-
MPMovieControlModeHiddenDo not display any controls. This mode prevents the user from controlling playback.
Available in iOS 2.0 through iOS 7.1.
Import Statement
Objective-C
@import MediaPlayer;Availability
Available in iOS 2.0 through iOS 7.1.
-
-
Posted when the duration of a movie has been determined. There is no
userInfodictionary.To retrieve the duration of a movie, access the movie player’s
durationproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMovieDurationAvailableNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when the available media types in a movie are determined. There is no
userInfodictionary.To retrieve the available media types in a movie—audio, video, or both—access the movie player’s
movieMediaTypesproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMovieMediaTypesAvailableNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when the natural frame size of a movie is first determined or subsequently changes. There is no
userInfodictionary.To retrieve the natural frame size for a movie, access the movie player’s
naturalSizeproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMovieNaturalSizeAvailableNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when a movie is in memory and ready to play. The movie player whose state has changed is available as the object associated with the notification. If an error occurred during loading, the
userInfodictionary of this notification contains a key with the name “error” whose value is theNSErrorobject describing the problem.Use the
MPMoviePlayerLoadStateDidChangeNotificationnotification to determine the readiness of the player.Import Statement
Objective-C
@import MediaPlayer;Availability
Available in iOS 2.0 through iOS 7.1.
Deprecated in iOS 3.2.
-
Posted when a movie player has entered full-screen mode. There is no
userInfodictionary.A movie player can enter full screen mode programmatically (see the
setFullscreen:animated:method) or by user interaction. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerDidEnterFullscreenNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when a movie player has exited full-screen mode. There is no
userInfodictionary.A movie player can exit full screen mode programmatically (see the
setFullscreen:animated:method) or by user interaction. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerDidExitFullscreenNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
MPMoviePlayerIsAirPlayVideoActiveDidChangeNotification MPMoviePlayerIsAirPlayVideoActiveDidChangeNotificationPosted when a movie player has started or ended playing a movie via AirPlay. There is no
userInfodictionary.To find out whether AirPlay playback started or stopped, query the
airPlayVideoActiveproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerIsAirPlayVideoActiveDidChangeNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 5.0 and later.
Deprecated in iOS 9.0.
-
Posted when a movie player’s network buffering state has changed. There is no
userInfodictionary.To retrieve the current load state of a movie player, access its
loadStateproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerLoadStateDidChangeNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when the currently playing movie has changed. There is no
userInfodictionary.To retrieve the URL for currently playing movie, access the movie player’s
contentURLproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerNowPlayingMovieDidChangeNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when a movie has finished playing. The
userInfodictionary of this notification contains theMPMoviePlayerPlaybackDidFinishReasonUserInfoKeykey, which indicates the reason that playback finished. This notification is also sent when playback fails because of an error.The movie player whose state has changed is available as the object associated with the notification.
This notification is not sent when a movie is displaying in fullscreen mode and the user taps Done. The Done button pauses playback and causes the movie player to exit fullscreen mode. To detect this scenario, register for other notifications such as
MPMoviePlayerDidExitFullscreenNotification.Declaration
Swift
let MPMoviePlayerPlaybackDidFinishNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
Posted when a movie player’s playback state has changed. There is no
userInfodictionary.Playback state can change programmatically (see MPMediaPlayback Protocol Reference) or by user interaction. To retrieve the playback state of a movie player, access its
playbackStateproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerPlaybackStateDidChangeNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when the scaling mode of a movie player has changed. There is no
userInfodictionary.Scaling mode can change programmatically or by user interaction. To set or retrieve the scaling mode of a movie player, access its
scalingModeproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerScalingModeDidChangeNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 2.0 and later.
Deprecated in iOS 9.0.
-
MPMoviePlayerThumbnailImageRequestDidFinishNotification MPMoviePlayerThumbnailImageRequestDidFinishNotificationPosted when a request to capture a thumbnail from a movie has finished whether the request succeeded or failed. Upon successful capture of a thumbnail, the
userInfodictionary contains values for the following keys:If the capture request finished with an error, the
userInfodictionary contains values for the following two keys:The movie player whose state has changed is available as the object associated with the notification. The methods to use for capturing movie thumbnails are described in Generating Thumbnail Images.
Declaration
Swift
let MPMoviePlayerThumbnailImageRequestDidFinishNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when a movie player is about to enter full-screen mode. The
userInfodictionary contains keys whose values describe the transition animation used to enter full-screen mode. See Fullscreen Notification Keys.A movie player can enter full screen mode programmatically (see the
setFullscreen:animated:method) or by user interaction. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerWillEnterFullscreenNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when a movie player is about to exit full-screen mode. The
userInfodictionary contains keys whose values describe the transition animation used to exit full-screen mode. See Fullscreen Notification Keys.A movie player can exit full screen mode programmatically (see the
setFullscreen:animated:method) or by user interaction. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerWillExitFullscreenNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when the source type of a movie was previously unknown and is newly available. There is no
userInfodictionary.To retrieve the source type of the movie, access the movie player’s
movieSourceTypeproperty. The movie player whose state has changed is available as the object associated with the notification.Declaration
Swift
let MPMovieSourceTypeAvailableNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 3.2 and later.
Deprecated in iOS 9.0.
-
Posted when the ready for display state changes.
To check whether a movie player is ready for display, access its
readyForDisplayproperty. The movie player whose display state has changed is available as the object associated with the notification.Declaration
Swift
let MPMoviePlayerReadyForDisplayDidChangeNotification: StringImport Statement
Objective-C
@import MediaPlayer;Swift
import MediaPlayerAvailability
Available in iOS 6.0 and later.
Deprecated in iOS 9.0.
Copyright © 2015 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2015-10-21
