Contents

Media Player

Find and play songs, audio podcasts, audio books, and more from within your app.

Overview

Use the Media Player framework, which is part of MusicKit, to control playback of the user’s media from your app. If your app incorporates music, you can use this framework to search for audio content, such as songs, podcasts, and books, in the user’s library. You can then play that content directly or ask the system Music app to play it. For example, a game might give users the option to play their own music while completing a particular game level.

To play content from the user’s library using the Media Player framework, use one of the built-in MPMusicPlayerController objects:

  • An application player plays music locally within your app. Use this player when you want greater control over the audio you play for the user. This player doesn’t change the state of the built-in Music app.

  • The system player employs the Music app to play audio on your behalf. Use this player when you want audio to continue playing even when the user switches away from your app.

Use media queries to retrieve the items you want to play and to populate the queue for the media player you select. After a user gives your app permission to access their Apple Music account, it can add songs, create playlists, and play songs from Apple Music. If your app detects that the user isn’t an Apple Music subscriber, it can offer a trial.

You can’t play video media items directly using the Media Player framework. To play videos containing MPMediaItem objects, use an AVPlayer object from AVFoundation. The system player also provides a way to play video items using the system apps.

Topics

Essentials

Built-in music playback

Media library synchronization

Media item queries

Media player queues

Media items and playlists

Media player user interface

Now Playing information

External player and system event handling

External media player items

Media player errors

Deprecated

Classes

Variables