iOS Developer Library — Pre-Release

Developer

MediaPlayer Framework Reference MPMoviePlayerController Class Reference

Options
Deployment Target:

On This Page
Language:

MPMoviePlayerController

Inheritance


Conforms To


Import Statement


Swift

import MediaPlayer

Objective-C

@import MediaPlayer;

Availability


Available in iOS 2.0 and later.

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: 80
  • protocol: @"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: credential
  • forProtectionSpace: 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.

  • init(contentURL:) - initWithContentURL: Designated Initializer

    Returns a MPMoviePlayerController object initialized with the movie at the specified URL.

    Declaration

    Swift

    init!(contentURL url: NSURL!)

    Objective-C

    - (instancetype)initWithContentURL:(NSURL *)url

    Parameters

    url

    The 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 prepareToPlay method, described in MPMediaPlayback Protocol Reference.

    To be notified when a new movie player is ready to play, register for the MPMoviePlayerLoadStateDidChangeNotification notification. You can then check load state by accessing the loadState property.

    To check for errors in URL loading, register for the MPMoviePlayerPlaybackDidFinishNotification notification. On error, this notification contains an NSError object available using the @"error" key in the notification’s userInfo dictionary.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 2.0 and later.

  • The URL that points to the movie file.

    Declaration

    Swift

    @NSCopying var contentURL: NSURL!

    Objective-C

    @property(nonatomic, copy) NSURL *contentURL

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 2.0 and later.

  • The playback type of the movie.

    Declaration

    Swift

    var movieSourceType: MPMovieSourceType

    Objective-C

    @property(nonatomic) MPMovieSourceType movieSourceType

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • The types of media available in the movie. (read-only)

    Declaration

    Swift

    var movieMediaTypes: MPMovieMediaTypeMask { get }

    Objective-C

    @property(nonatomic, readonly) MPMovieMediaTypeMask movieMediaTypes

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Specifies whether the movie player allows AirPlay movie playback.

    Declaration

    Swift

    var allowsAirPlay: Bool

    Objective-C

    @property(nonatomic) BOOL allowsAirPlay

    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 to NOfalse.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 4.3 and later.

  • 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 airPlayVideoActive

    Discussion

    You can query this property after receiving an MPMoviePlayerIsAirPlayVideoActiveDidChangeNotification notification to find out whether the AirPlay video started or stopped.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 5.0 and later.

  • The width and height of the movie frame. (read-only)

    Declaration

    Swift

    var naturalSize: CGSize { get }

    Objective-C

    @property(nonatomic, readonly) CGSize naturalSize

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • A Boolean that indicates whether the movie player is in full-screen mode.

    Declaration

    Swift

    var fullscreen: Bool

    Objective-C

    @property(nonatomic, getter=isFullscreen) BOOL fullscreen

    Discussion

    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 the setFullscreen: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 MPMoviePlayerWillEnterFullscreenNotification and MPMoviePlayerDidEnterFullscreenNotification notifications. Upon exiting from full-screen mode, it posts MPMoviePlayerWillExitFullscreenNotification and MPMoviePlayerDidExitFullscreenNotification notifications.

    The value of this property may also change as a result of the user interacting with the movie player controls.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Causes the movie player to enter or exit full-screen mode.

    Declaration

    Swift

    func setFullscreen(_ fullscreen: Bool, animated animated: Bool)

    Objective-C

    - (void)setFullscreen:(BOOL)fullscreen animated:(BOOL)animated

    Parameters

    fullscreen

    Specify YEStrue to enter full-screen mode or NOfalse to exit full-screen mode.

    animated

    Specify YEStrue to animate the transition between modes or NOfalse to switch immediately to the new mode.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

    See Also

    fullscreen

  • The scaling mode to use when displaying the movie.

    Declaration

    Swift

    var scalingMode: MPMovieScalingMode

    Objective-C

    @property(nonatomic) MPMovieScalingMode scalingMode

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 2.0 and later.

  • The style of the playback controls.

    Declaration

    Swift

    var controlStyle: MPMovieControlStyle

    Objective-C

    @property(nonatomic) MPMovieControlStyle controlStyle

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • 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 useApplicationAudioSession

    Discussion

    The default value of this property is YEStrue. Setting this property to NOfalse causes 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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Availability

    Available in iOS 3.2 and later.

    Deprecated in iOS 6.0.

  • duration duration Property

    The duration of the movie, measured in seconds. (read-only)

    Declaration

    Swift

    var duration: NSTimeInterval { get }

    Objective-C

    @property(nonatomic, readonly) NSTimeInterval duration

    Discussion

    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 a MPMovieDurationAvailableNotification notification is posted.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • The amount of currently playable content. (read-only)

    Declaration

    Swift

    var playableDuration: NSTimeInterval { get }

    Objective-C

    @property(nonatomic, readonly) NSTimeInterval playableDuration

    Discussion

    For progressively downloaded network content, this property reflects the amount of content that can be played now.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • view view Property

    The view containing the movie content and controls. (read-only)

    Declaration

    Swift

    var view: UIView! { get }

    Objective-C

    @property(nonatomic, readonly) UIView *view

    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 loadView or viewDidLoad method of the custom view controller that presents your view hierarchy. You are free to change the view’s frame rectangle to accommodate the space available in your view hierarchy. The movie player uses the value in the scalingMode property 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 MPMoviePlayerViewController class 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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

    See Also

    backgroundView

  • A customizable view that is displayed behind the movie content. (read-only)

    Declaration

    Swift

    var backgroundView: UIView! { get }

    Objective-C

    @property(nonatomic, readonly) UIView *backgroundView

    Discussion

    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 view property.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

See also the methods of the MPMediaPlayback protocol.

  • loadState loadState Property

    The network load state of the movie player. (read-only)

    Declaration

    Swift

    var loadState: MPMovieLoadState { get }

    Objective-C

    @property(nonatomic, readonly) MPMovieLoadState loadState

    Discussion

    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 MPMoviePlayerLoadStateDidChangeNotification notification.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • The current playback state of the movie player. (read-only)

    Declaration

    Swift

    var playbackState: MPMoviePlaybackState { get }

    Objective-C

    @property(nonatomic, readonly) MPMoviePlaybackState playbackState

    Discussion

    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 the MPMoviePlayerPlaybackStateDidChangeNotification notification.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • The time, specified in seconds within the video timeline, when playback should start.

    Declaration

    Swift

    var initialPlaybackTime: NSTimeInterval

    Objective-C

    @property(nonatomic) NSTimeInterval initialPlaybackTime

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.0 and later.

  • The end time (measured in seconds) for playback of the movie.

    Declaration

    Swift

    var endPlaybackTime: NSTimeInterval

    Objective-C

    @property(nonatomic) NSTimeInterval endPlaybackTime

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • A Boolean that indicates whether a movie should begin playback automatically.

    Declaration

    Swift

    var shouldAutoplay: Bool

    Objective-C

    @property(nonatomic) BOOL shouldAutoplay

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • 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 readyForDisplay

    Discussion

    The default value of this property is NOfalse. This property returns YEStrue if the first video frame is ready to be displayed and returns NOfalse if there are no video tracks associated. When the value of this property changes to YEStrue, a MPMoviePlayerReadyForDisplayDidChangeNotification is sent.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 6.0 and later.

  • Determines how the movie player repeats the playback of the movie.

    Declaration

    Swift

    var repeatMode: MPMovieRepeatMode

    Objective-C

    @property(nonatomic) MPMovieRepeatMode repeatMode

    Discussion

    The default value of this property is MPMovieRepeatModeNone. For a list of available repeat modes, see MPMovieRepeatMode.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Obtains the most recent time-based metadata provided by the streamed movie.

    Declaration

    Swift

    var timedMetadata: [AnyObject]! { get }

    Objective-C

    @property(nonatomic, readonly) NSArray *timedMetadata

    Return Value

    An array of the most recent MPTimedMetadata objects provided by the streamed movie.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 4.0 and later.

  • Requests a video ad to be played.

    Declaration

    Swift

    func playPrerollAdWithCompletionHandler(_ completionHandler: ((NSError!) -> Void)!)

    Objective-C

    - (void)playPrerollAdWithCompletionHandler:(void (^)(NSError *error))completionHandler

    Parameters

    completionHandler

    The block to be invoked after the system has played or failed to play a pre-roll ad. The error argument 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 ADError for a complete list of possible errors.

    Discussion

    The iAdPreroll category adds support for pre-roll video ads to MPMoviePlayerController objects.

    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 iAd

    Availability

    Available in iOS 7.0 and later.

  • Captures and returns a thumbnail image from the current movie.

    Declaration

    Objective-C

    - (UIImage *)thumbnailImageAtTime:(NSTimeInterval)playbackTime timeOption:(MPMovieTimeOption)option

    Parameters

    playbackTime

    The time at which to capture the thumbnail image. The time value represents the number of seconds from the beginning of the current movie.

    option

    The 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 nil if the thumbnail could not be captured.

    Discussion

    This method captures the thumbnail image synchronously from the current movie (which is accessible from the MPMovieSourceTypeUnknown property).

    Import Statement

    Objective-C

    @import MediaPlayer;

    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]!, timeOption option: MPMovieTimeOption)

    Objective-C

    - (void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option

    Parameters

    playbackTimes

    An array of NSNumber objects 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.

    option

    The 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 MPMoviePlayerThumbnailImageRequestDidFinishNotification notification 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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Cancels all pending asynchronous thumbnail image requests.

    Declaration

    Swift

    func cancelAllThumbnailImageRequests()

    Objective-C

    - (void)cancelAllThumbnailImageRequests

    Discussion

    This method cancels only requests made using the requestThumbnailImagesAtTimes:timeOption: method. It does not cancel requests made synchronously using the thumbnailImageAtTime:timeOption: method.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • accessLog accessLog Property

    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 *accessLog

    Discussion

    Can be nil. For information about movie access logs, refer to MPMovieAccessLog Class Reference.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 4.3 and later.

  • errorLog errorLog Property

    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 *errorLog

    Discussion

    Can be nil. For information about movie error logs, refer to MPMovieErrorLog Class Reference.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 4.3 and later.

The following methods and properties are no longer available as of iOS 3.2 and must not be used.

  • backgroundColor backgroundColor Available in iOS 2.0 through iOS 7.1 Property

    The color of the background area behind the movie.

    Deprecation Statement

    Get the view from the backgroundView property and set its color directly.

    Declaration

    Objective-C

    - (UIColor *)backgroundColor

    Discussion

    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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Availability

    Available in iOS 2.0 through iOS 7.1.

    Deprecated in iOS 3.2.

  • movieControlMode movieControlMode Available in iOS 2.0 through iOS 7.1 Property

    The user controls to display.

    Deprecation Statement

    Use the controlStyle property instead.

    Declaration

    Objective-C

    - (MPMovieControlMode)movieControlMode

    Discussion

    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 MPMovieControlModeDefault by default. See the MPMovieControlMode enumeration for the available control modes.

    Import Statement

    Objective-C

    @import MediaPlayer;

    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 : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: 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

    • Unknown

      MPMovieLoadStateUnknown

      The load state is not known.

      Available in iOS 3.2 and later.

    • Playable

      MPMovieLoadStatePlayable

      The 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.

    • PlaythroughOK

      MPMovieLoadStatePlaythroughOK

      Enough data has been buffered for playback to continue uninterrupted.

      Available in iOS 3.2 and later.

    • Stalled

      MPMovieLoadStateStalled

      The 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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    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 }

    Objective-C

    enum { MPMovieControlStyleNone, MPMovieControlStyleEmbedded, MPMovieControlStyleFullscreen, MPMovieControlStyleDefault = MPMovieControlStyleFullscreen }; typedef NSInteger MPMovieControlStyle;

    Constants

    • None

      MPMovieControlStyleNone

      No controls are displayed.

      Available in iOS 3.2 and later.

    • Embedded

      MPMovieControlStyleEmbedded

      Controls 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.

    • Fullscreen

      MPMovieControlStyleFullscreen

      Controls 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.

    • MPMovieControlStyleDefault

      MPMovieControlStyleDefault

      Fullscreen controls are displayed by default.

      Available in iOS 3.2 and later.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    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

    • PlaybackEnded

      MPMovieFinishReasonPlaybackEnded

      The end of the movie was reached.

      Available in iOS 3.2 and later.

    • PlaybackError

      MPMovieFinishReasonPlaybackError

      There was an error during playback.

      Available in iOS 3.2 and later.

    • UserExited

      MPMovieFinishReasonUserExited

      The user stopped playback.

      Available in iOS 3.2 and later.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    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

    • Stopped

      MPMoviePlaybackStateStopped

      Playback is currently stopped. Playback will commence from the beginning of the movie.

      Available in iOS 3.2 and later.

    • Playing

      MPMoviePlaybackStatePlaying

      Playback is currently under way.

      Available in iOS 3.2 and later.

    • Paused

      MPMoviePlaybackStatePaused

      Playback is currently paused. Playback will resume from the point where it was paused.

      Available in iOS 3.2 and later.

    • Interrupted

      MPMoviePlaybackStateInterrupted

      Playback is temporarily interrupted, perhaps because the buffer ran out of content.

      Available in iOS 3.2 and later.

    • SeekingForward

      MPMoviePlaybackStateSeekingForward

      The movie player is currently seeking towards the end of the movie.

      Available in iOS 3.2 and later.

    • SeekingBackward

      MPMoviePlaybackStateSeekingBackward

      The movie player is currently seeking towards the beginning of the movie.

      Available in iOS 3.2 and later.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    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

    • None

      MPMovieRepeatModeNone

      Content is not repeated when playback finishes

      Available in iOS 3.2 and later.

    • One

      MPMovieRepeatModeOne

      The current movie is repeated when it finishes.

      Available in iOS 3.2 and later.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    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

    • None

      MPMovieScalingModeNone

      Do not scale the movie.

      Available in iOS 2.0 and later.

    • AspectFit

      MPMovieScalingModeAspectFit

      Scale 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.

    • AspectFill

      MPMovieScalingModeAspectFill

      Scale 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.

    • Fill

      MPMovieScalingModeFill

      Scale 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.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    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

    • NearestKeyFrame

      MPMovieTimeOptionNearestKeyFrame

      Generate 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.

    • Exact

      MPMovieTimeOptionExact

      Use the exact current frame.

      Available in iOS 3.2 and later.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Specifies the types of content available in the movie file.

    Declaration

    Swift

    struct MPMovieMediaTypeMask : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: 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

    • None

      MPMovieMediaTypeMaskNone

      The types of media available in the media are not yet known.

      Available in iOS 3.2 and later.

    • Video

      MPMovieMediaTypeMaskVideo

      The movie file contains video media.

      Available in iOS 3.2 and later.

    • Audio

      MPMovieMediaTypeMaskAudio

      The movie file contains audio media.

      Available in iOS 3.2 and later.

    Discussion

    You can OR the specified constants together to specify a movie

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    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

    • Unknown

      MPMovieSourceTypeUnknown

      The movie type is not yet known.

      Available in iOS 3.2 and later.

    • File

      MPMovieSourceTypeFile

      The movie is a local file or is a file that can be downloaded from the network.

      Available in iOS 3.2 and later.

    • Streaming

      MPMovieSourceTypeStreaming

      The movie is a live or on-demand stream.

      Available in iOS 3.2 and later.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • The following keys may be found in the userInfo dictionary of a MPMoviePlayerThumbnailImageRequestDidFinishNotification notification.

    Declaration

    Swift

    let MPMoviePlayerThumbnailImageKey: String let MPMoviePlayerThumbnailTimeKey: String let MPMoviePlayerThumbnailErrorKey: String

    Objective-C

    NSString *const MPMoviePlayerThumbnailImageKey; NSString *const MPMoviePlayerThumbnailTimeKey; NSString *const MPMoviePlayerThumbnailErrorKey;

    Constants

    • MPMoviePlayerThumbnailImageKey

      MPMoviePlayerThumbnailImageKey

      The value of this key is a UIImage object containing the image that was obtained for the desired frame.

      Available in iOS 3.2 and later.

    • MPMoviePlayerThumbnailTimeKey

      MPMoviePlayerThumbnailTimeKey

      The value of this key is a NSNumber object 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.

    • MPMoviePlayerThumbnailErrorKey

      MPMoviePlayerThumbnailErrorKey

      The value of this key is an NSError object identifying the error that occurred, if any.

      Available in iOS 3.2 and later.

  • The following keys may be found in the userInfo dictionary of notifications for transitioning in or out of full-screen mode.

    Declaration

    Swift

    let MPMoviePlayerFullscreenAnimationDurationUserInfoKey: String let MPMoviePlayerFullscreenAnimationCurveUserInfoKey: String

    Objective-C

    NSString *const MPMoviePlayerFullscreenAnimationDurationUserInfoKey; NSString *const MPMoviePlayerFullscreenAnimationCurveUserInfoKey;

    Constants

    • MPMoviePlayerFullscreenAnimationDurationUserInfoKey

      MPMoviePlayerFullscreenAnimationDurationUserInfoKey

      The value of this key is an NSNumber containing 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.

    • MPMoviePlayerFullscreenAnimationCurveUserInfoKey

      MPMoviePlayerFullscreenAnimationCurveUserInfoKey

      The value of this key is an NSNumber containing an integer value that represents one of the UIViewAnimationCurve constants.

      Available in iOS 3.2 and later.

  • The following key may be found in the userInfo dictionary of a MPMoviePlayerPlaybackDidFinishNotification notification.

    Declaration

    Swift

    let MPMoviePlayerPlaybackDidFinishReasonUserInfoKey: String

    Objective-C

    NSString *const MPMoviePlayerPlaybackDidFinishReasonUserInfoKey;

    Constants

    • MPMoviePlayerPlaybackDidFinishReasonUserInfoKey

      MPMoviePlayerPlaybackDidFinishReasonUserInfoKey

      The value of this key is an NSNumber containing an integer value that represents one of the “MPMovieFinishReason” constants.

      Available in iOS 3.2 and later.

  • Options for displaying movie playback controls.

    Use the “MPMovieControlStyle” constants in conjunction with the controlStyle property instead.

    Declaration

    Objective-C

    typedef enum { MPMovieControlModeDefault, MPMovieControlModeVolumeOnly, MPMovieControlModeHidden } MPMovieControlMode;

    Constants

    • MPMovieControlModeDefault

      MPMovieControlModeDefault

      Display 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.

    • MPMovieControlModeVolumeOnly

      MPMovieControlModeVolumeOnly

      Display volume controls only.

      Available in iOS 2.0 through iOS 7.1.

    • MPMovieControlModeHidden

      MPMovieControlModeHidden

      Do 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.