Add the ability to find and play songs, audio podcasts, audio books, and more from within your app.
- iOS 2.0+
- macOS 10.12.1+
- tvOS 9.0+
- watchOS 5.0+
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
MPMedia 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.