Framework

Media Player

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

Overview

The Media Player framework provides developers with several ways to play media. Built-in music players provide an easy way to access and play audio from the user's music library in your app. External music players can also retrieve and play media items from the user's music library. To enable users to play videos containing MPMediaItem objects, use AVPlayer. You cannot play video media items using the Media Player framework.

Use one of the built-in music players to enable users to play audio selections from their music library in 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.

Incorporate MusicKit to allow users to play Apple Music and their local music library natively from your apps and games. After a user provides permission to their Apple Music account, your app can create playlists, add songs to their library, and play any of the millions of songs in the Apple Music catalog. If your app detects that the user is not yet an Apple Music member, you can offer a trial from within your app.

You can incorporate one of two types of built-in 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.

Topics

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.

class MPMusicPlayerController

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

protocol MPMediaPlayback

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

protocol MPSystemMusicPlayerController

A protocol for playing videos in the Music app.

Media Library Synchronization

class MPMediaLibrary

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

Media Item Queries

Using Filters to Create Specialized Queries

Add a filter set to a query before populating a music player queue.

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

class MPMediaQuerySection

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

class MPMediaPropertyPredicate

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

class MPMediaPredicate

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

Media Player Queues

class MPMusicPlayerControllerQueue

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

class MPMusicPlayerControllerMutableQueue

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

class MPMusicPlayerApplicationController

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

class MPMusicPlayerMediaItemQueueDescriptor

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

class MPMusicPlayerStoreQueueDescriptor

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

class MPMusicPlayerPlayParametersQueueDescriptor

A set of properties and methods used to modify how items are played, based on play parameters returned from MusicKit API results.

class MPMusicPlayerQueueDescriptor

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

Media Items and Playlists

class MPMediaItem

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

class MPMediaItemArtwork

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

class MPMediaItemCollection

A sorted set of media items from the media library.

class MPMediaPlaylist

A playable collection of related media items.

class MPMediaPlaylistCreationMetadata

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

class MPMediaEntity

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

Media Player User Interface

Adding Individual Media Items Using a Media Picker

Add a media picker to your app to allow users to pick individual music items.

class MPMediaPickerController

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

class MPVolumeView

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

Global Volume Setting Methods

Global functions for setting the volume alert window status.

Now Playing Information

Provide information about the current track.

class MPNowPlayingInfoCenter

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

class MPNowPlayingInfoLanguageOption

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

class 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

Support playback controls on external media players or the controls displayed by the system.

Handling External Player Events Notifications

Handle events for external media players.

Remote Command Center Events

Set up the remote command center to handle media player events.

Track Navigation Events

Respond to requests to change what part of a media item is played.

Media Playback Mode Events

Respond to changes in how media items are played.

Feedback and Rating Events

Respond to incoming feedback and rating events.

External Media Player Items

Provide content and interact with external media players.

class MPContentItem

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

class MPPlayableContentManager

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

class MPPlayableContentManagerContext

An object representing the current state of the playable endpoint.

Errors

struct MPError

Error codes for the MPError domain.

enum MPError.Code

Error codes for the Media Player error domain.

let MPErrorDomain: String

The Media Player framework error domain.

Deprecated

Deprecated Symbols

These symbols are deprecated and are no longer recommended.