Framework

MediaPlayer

Add the ability to find and play media items including songs, audio podcasts, and audio books from within your app.

Overview

Use the MediaPlayer framework to enable users to play music, audio podcasts, and audio books from within your app. For example, you give users the option to play their own music from within your app while they try to complete a particular game level. Through MediaPlayer, your app can access media items synced from iTunes, iCloud Music Library, and Apple Music Subscription. It can also access non-Apple media items that users have stored on their devices. After being granted access to a user's media items, you can play them and add more to the user's device. Library access is read-only.

You can incorporate one of two types of media player into your app, depending on your goal. Use a system player if you want changes made in your app to also affect the Music app. Use an application player if you want to leave the Music app as is while playing audio. After deciding on the player, use media queries to retrieve media items that will populate the player.

To enable users to play videos containing MPMediaItem objects, use AVPlayer. You cannot play video media items using the MediaPlayer framework.

Event Handling

Apps that play audio or video content receive player events to start and stop playback, change tracks, and even rate an item. All media apps should support these events.

To receive player events, do the following:

• Use the shared MPRemoteCommandCenter object to register handlers for the events you wish to handle and to disable the events you are not interested in receiving.

• Begin playing audio. Your app must be the Now Playing app. An app does not receive remote control events until it begins playing audio. Test that your app is properly receiving and handling remote control events with Control Center, which you access by swiping up from the bottom edge of your screen. These controls send remote control events to the app that is currently or was most recently playing audio. You can also access the playback controls from the lock screen of the device.

Symbols

Media Library Synchronization

MPMediaLibrary

An object that represents the state of synced media items on a device.

Media Player Basics

The media player provides the ability to play audio media items stored on a user's device from within your app.

MPMediaPlayback

A protocol that defines the interface for controlling audio media playback.

MPMusicPlayerController

An object used to play audio media items from the device's Music app library.

MPMusicPlayerMediaItemQueueDescriptor

A set of properties and methods used to modify audio media items in the player's media queue.

MPMusicPlayerQueueDescriptor

The abstract base class for audio media item and store queue descriptors.

MPMusicPlayerStoreQueueDescriptor

A set of properties and methods used to modify items, based on their store identifier, in the player's queue.

Media Item Queries

MPMediaPredicate

An abstract class that defines classes for filtering media in a media query.

MPMediaPropertyPredicate

A set of predicates that define a filter used in a media query.

MPMediaQuery

A query that specifies a set of media items from the device's media library by way of a filter and a grouping type.

MPMediaQuerySection

A range of media items or media item collections from within a media query.

Media Player Queues

MPMusicPlayerApplicationController

A media player object that you use to revise the queue representing currently playing.

MPMusicPlayerControllerMutableQueue

A mutable queue containing the media items to be played by the media player.

MPMusicPlayerControllerQueue

An immutable queue containing the media items to be played by an application queue media player.

Media Items and Playlists

MPMediaEntity

The abstract superclass for media items, media item collections, and media playlist instances.

MPMediaItem

A collection of properties that represents a single item contained in the media library.

MPMediaItemArtwork

A graphical image, such as music album cover art, associated with a media item.

MPMediaItemCollection

A sorted set of media items from the media library.

MPMediaPlaylistAttribute

Attributes define the type of playlist.

MPMediaPlaylist

A playable collection of related media items.

MPMediaPlaylistCreationMetadata

A set of attributes used to describe a playlist when the playlist is first created.

Media Player User Interface

MPVolumeView

A slider control used to set the system audio output volume, and a button for choosing the audio output route.

MPMediaPickerController

A specialized view controller that provides a graphical interface for selecting media items.

MPMediaPickerControllerDelegate

The protocol you implement so that a media item picker can respond to a user making media item selections.

Global Volume Setting Methods

Global functions for setting the volume alert window status.

Now Playing Information

Use this class to provide information about the current track.

MPNowPlayingInfoCenter

An object that you use to set now-playing information for media being played by your app.

Multiple Language Support

MPNowPlayingInfoLanguageOption

A set of interfaces used to set the language option for the now-playing item.

MPNowPlayingInfoLanguageOptionGroup

A grouped set of language options where only a single language option can be active at a time.

Language Option Characteristic Constants

The constants used to define language characteristics.

External Player and System Event Handling

Use these classes to support playback controls on external media players or the controls displayed by the system.

Setting up the Remote Event Handler

Classes that you use to set up remote event handling.

Responding to Track Navigation Events

Classes that respond to requests to change what part of a media item is played.

Responding to Changes to Media Playback Mode Events

Classes that respond to changes in how media items are played.

Responding to Feedback and Rating Events

Classes that handle incoming feedback and rating events.

Error Handling

let MPErrorDomain: String

The MediaPlayer framework error domain.

MPError.Code

Error codes for the MediaPlayer error domain.

MPError

Error codes for the MPError domain.

External Media Player Items

Provide content and interact with external media players.

MPContentItem

An object containing the information for a particular media item that is displayed to the user.

MPPlayableContentDataSource

The data source providing media metadata to external media players so they can build user interfaces displaying your app’s content.

MPPlayableContentDelegate

The protocol used to let external media players send playback commands to an app.

MPPlayableContentManager

A shared content manager used to control interactions between your media app and system-provided or external media player interfaces.

MPPlayableContentManagerContext

An object representing the current state of the playable endpoint.

Extended Types

AVMediaSelectionGroup

An AVMediaSelectionGroup represents a collection of mutually exclusive options for the presentation of media within an asset.

AVMediaSelectionOption

An AVMediaSelectionOption object represents a specific option for the presentation of media within a group of options.

NSNotification.Name

The type used for the name of a notification.

UIViewController

Provides the infrastructure for managing the views of your UIKit app.

Deprecated

MPMovieAccessLog

Key metrics about network playback for an associated movie player that is playing streamed content.

Deprecated
MPMovieAccessLogEvent

A single piece of information for a movie access log.

Deprecated
MPMovieErrorLog

Data describing network resource playback failures for the associated movie player, including timestamps indicating when each failure occurred.

Deprecated
MPMovieErrorLogEvent

A single piece of information for a movie error log.

Deprecated
MPMovieLoadState

Constants describing the network load state of the movie player.

Deprecated
MPMovieMediaTypeMask

The types of content available in the movie file.

Deprecated
MPMoviePlayerController

A type of movie player that manages the playback of a movie from a file or a network stream.

Deprecated
MPMoviePlayerViewController

A simple view controller for displaying full-screen movies.

Deprecated
MPTimedMetadata

A timed metadata object that carries time-based information within HTTP streamed media.

Deprecated