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


@interface MPMusicPlayerController : NSObject


Create an instance of a music player to play media items in your app. There are two types of music player:

  • An application music player plays music locally within your app. It is not aware of the Music app’s now-playing item, nor does it affect the Music app’s state. There are two application music players: applicationMusicPlayer and applicationQueuePlayer. The application queue player provides greater control over the contents of the queue and is the preferred player.

  • The system music player employs the built-in Music app on your behalf. On instantiation, it takes on the current Music app state, such as the identification of the now-playing item. If a user switches away from your app while music is playing, that music continues to play. The Music app then has your music player’s most recently-set repeat mode, shuffle mode, playback state, and now-playing item.

Creating a new instance of MPMusicPlayerController and not specifying the player type returns a system music player.

Home Sharing and System Music Players

The built-in Music and Videos apps can play media from shared libraries using Home Sharing. However, third-party apps using the Media Player framework still have access only to the device Music library. This means that your app cannot display the title of a home-shared song in your user interface. Specifically, if the Music app is playing a home-shared song, and you are using an Music music player, the value of the nowPlayingItem property of your music player is nil. Other playback information is available, however, when playing shared media. For example, the system does update the value of the playbackState property when the system music player is playing a shared item.

Using Remote-Control Events with a Music Player

Users can initiate audio playback commands through an external headset or accessory. These commands are sent to the app as remote-control events. To receive remote-control events in your app, you must use an application music player. If you use the system music player, your app uses the Music app to play audio, which means that the Music app is the “now playing” app. The Music app receives the remote control events, not your app. However, the Music app responds to remote control events on your behalf. For example, if your app plays audio using the system music player, and you switch from your app to the iOS device’s Now Playing controls, the controls work as expected. That is, you can play or pause audio or skip to the next and previous items.


Getting a Music Player


Returns the application music player.


Returns the application queue music player.


Returns the system music player, which controls the Music app’s state.


Returns the iPod music player, which controls the iPod app’s state.


Setting Up a Playback Queue

Before a music player can produce sound, it needs a playback queue. You provide the music player with its playback queue, which specifies the media items to be played.

- setQueueWithQuery:

Sets a music player’s playback queue based on a media query.

- setQueueWithItemCollection:

Sets a music player’s playback queue using a media item collection.

- setQueueWithStoreIDs:

Sets a music player's playback queue using with media items identified by the store identifiers.

- setQueueWithDescriptor:

Set the music player's playback queue using media items that fit the queue descriptor properties.

Playing a Media Item

- prepareToPlayWithCompletionHandler:

Prepares a music player for playback.

Managing Playback Mode and State


The currently-playing media item, or the media item, within a queue, that you have designated to begin playback with.


The index of the now playing item in the current playback queue.


The current playback state of the music player.


The current repeat mode of the music player.


The current shuffle mode of the music player.


The music player playback state modes.


The repeat modes for the media player.


The shuffle modes for the media player.


The audio playback volume for the music player, in the range from 0.0 (silent) through 1.0 (maximum volume).


Controlling Playback

- skipToNextItem

Starts playback of the next media item in the playback queue; or, the music player is not playing, designates the next media item as the next to be played.

- skipToBeginning

Restarts playback at the beginning of the currently playing media item.

- skipToPreviousItem

Starts playback of the previous media item in the playback queue; or, the music player is not playing, designates the previous media item as the next to be played.

- appendQueueDescriptor:

Inserts the media items defined by the queue descriptor after the last media item in the current queue.

- prependQueueDescriptor:

Inserts the media items defined by the queue descriptor into the current queue immediately after the currently playing media item.

Using Music Player Notifications

These methods control the posting of playback notifications. You can nest calls to start or end these notifications.

- beginGeneratingPlaybackNotifications

Starts the generation of playback notifications.

- endGeneratingPlaybackNotifications

Ends the generation of playback notifications.


Posted when the playback state changes programmatically or by user action.


Posted when the currently playing media item has changed.


Posted when the audio playback volume for the music player has changed.


Inherits From

Conforms To

See Also

Built-In Music Playback

Playing Audio Using the Built-In Music Player

Create a media player inside your app to play audio from the user's media library.


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


A protocol for playing videos in the Music app.