iOS Developer Library

Developer

Media Player Framework Reference MPPlayableContentDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

MPPlayableContentDelegate

Use the MPPlayableContentDelegate protocol to let external media players send playback commands to an app. After the media player determines that a media item is to be played, the app’s content delegate requests for playback to be initiated.

  • Asks the delegate to begin playback of the specified content item.

    Declaration

    Swift

    optional func playableContentManager(_ contentManager: MPPlayableContentManager, initiatePlaybackOfContentItemAtIndexPath indexPath: NSIndexPath, completionHandler completionHandler: (NSError?) -> Void)

    Objective-C

    - (void)playableContentManager:(MPPlayableContentManager *)contentManager initiatePlaybackOfContentItemAtIndexPath:(NSIndexPath *)indexPath completionHandler:(void (^)(NSError *))completionHandler

    Parameters

    contentManager

    The content manager that initiated the request.

    indexPath

    The index for the indicated item.

    completionHandler

    A block to call after initiating a playback request.

    The block takes the following parameter:

    error

    If you have successfully begun playback, pass nil. If you cannot begin media playback due to an error, pass an NSError object.

    Discussion

    iOS calls this method when a media player interface needs to play a media item. Your app responds by beginning playback of the requested media item. After beginning playback, call the provided completionHandler block with an argument of nil; or, if your app cannot begin playback, call the completion handler with an NSError object describing the error.

    Availability

    Available in iOS 7.1 and later.

  • Asks the delegate to prepare suggested content for playback.

    Declaration

    Swift

    optional func playableContentManager(_ contentManager: MPPlayableContentManager, initializePlaybackQueueWithCompletionHandler completionHandler: (NSError?) -> Void)

    Objective-C

    - (void)playableContentManager:(MPPlayableContentManager *)contentManager initializePlaybackQueueWithCompletionHandler:(void (^)(NSError *))completionHandler

    Parameters

    contentManager

    The content manager that initiated the request.

    completionHandler

    A block to call after content is ready for playback.

    The block takes the following parameter:

    error

    If you have successfully prepared content for playback, pass nil. If you cannot prepare content due to an error, pass an NSError object.

    Discussion

    iOS calls this method when the user performs an action that, in context, might indicate intent to begin playing content using your app. For example, if the user frequently listens to audio content in your app with headphones while at a particular location, iOS might call this method upon plugging in headphones when the user is at that location. Your app responds by choosing appropriate content, performing any app-specific actions necessary to prepare the content for playback, and setting the nowPlayingInfo property of the shared MPNowPlayingInfoCenter object to indicate to the user that this content is ready to play.

    After preparing content for playing, call the provided completionHandler block with an argument of nil; or, if your app cannot prepare content, call the completion handler with an NSError object describing the error.

    Availability

    Available in iOS 9.0 and later.

  • Notifies the delegate that the playable content manager’s context information has changed.

    Declaration

    Swift

    optional func playableContentManager(_ contentManager: MPPlayableContentManager, didUpdateContext context: MPPlayableContentManagerContext)

    Objective-C

    - (void)playableContentManager:(MPPlayableContentManager *)contentManager didUpdateContext:(MPPlayableContentManagerContext *)context

    Parameters

    contentManager

    The content manager whose current context has changed.

    context

    The previous context of the content manager before the change.

    Discussion

    A playable content manager’s context provides information about the current playback environment of an external media player, such as whether that media player limits the amount of content that can be displayed. Use the content manager’s context property to examine attributes of the new context after the change.

    Availability

    Available in iOS 8.4 and later.