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+
The MediaPlayer 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 MediaPlayer 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. Through MediaPlayer, your app can access media items synced from iTunes, iCloud Music Library, and Apple Music Subscription. It can also access non-Apple media items that users have stored on their devices. After being granted access to a user's media items, you can play them and add more to the user's device.
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.