Find and play songs, audio podcasts, audio books, and more from within your app.
- iOS 2.0+
- macOS 10.12.1+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 5.0+
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.
To play content from the user's library using the Media Player framework, use one of the built-in
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 does not 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 is not yet an Apple Music member, you can also offer a trial from within your app.
You cannot 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.