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. MusicKit is 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 an entry under the “Privacy — Media Library Usage Description” key (NSAppleMusicUsageDescription
) justifying to the user your desire for access. This will appear in the alert that will be presented to the user on your behalf by the system (Figure 16-1).
Tip
Unlike some of the rather flippant examples in this book, your Info.plist privacy authorization texts must be meaningful ...
Get Programming iOS 12 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.