Chapter 16. Music Library
An iOS device can be used for the same purpose as the original iPod — to hold and play music, podcasts, and audiobooks. These items constitute the device’s music library. iOS provides the programmer with various forms of access to the music library; you can:
-
Explore the music library.
-
Play an item from the music library.
-
Control the Music app’s music player.
-
Present a standard interface where the user can select a music library item.
These features are all provided by the Media Player framework; you’ll need to import MediaPlayer
.
This chapter assumes that the user’s music library consists of sound files that are actually present on the device. However, the user might be using the iCloud Music Library (iTunes Match); and, starting in iOS 11, MusicKit allows your app to interface on the user’s behalf with the cloud-based Apple Music service. That’s beyond the scope of this book; see the Apple Music API Reference for information about it.
Music Library Authorization
Access to the music library requires authorization from the user. You’ll need to include in your Info.plist a meaningful entry under the “Privacy — Media Library Usage Description” key (NSAppleMusicUsageDescription
) justifying to the user your desire for access, to be displayed in the authorization alert that will be presented to the user on your behalf (Figure 16-1).
Get Programming iOS 13 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.