Find and play songs, audio podcasts, audio books, and more from within your app.
SDKs
- iOS 2.0+
- macOS 10.12.1+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 5.0+
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 (songs, podcasts, books, and so on) 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.
Important
To protect user privacy, users must grant permission for your app to access their music library. Add the NSApple
key to your app’s Info
file, and include a description of how you intend to use the user’s media. If this key isn’t present, the system terminates your app when it tries to access the user’s music.
To play content from the user’s library using the Media Player framework, use one of the built-in MPMusic
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 selected. After a user gives your app permission to access 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 isn’t yet an Apple Music member, you can also offer a trial from within your app.
You can’t play video media items directly using the Media Player framework. To play back videos containing MPMedia
objects, use an AVPlayer
object from AVFoundation. The system player also provides a way to play video items using the system apps.
Important
Use this framework only to facilitate the playback of the user’s audio content from your app. You’re not permitted to use this framework to gather information about the user’s audio content, or to use such information for any purpose other than audio playback within your app. For more information about accessing Apple Music content, see the App Store review guidelines.