Chapter 29. Music Library

An iOS device, in addition to running apps, can also be used for the same purpose as the original iPod — to hold and play music and podcasts. These items, usually moved onto the device by way of iTunes on a computer, constitute the device’s music library; the user can play them with the iPod app (which is called the Music app on some devices). Since version 3, iOS has provided the programmer with access to the device’s music library; this access has improved over time, and some aspects are as new as iOS 4.2. You can:

  • Explore the music library
  • Play an item from the music library
  • Learn and control what the iPod/Music app’s music player is doing
  • Present a standard interface for allowing the user to select a music library item

These abilities are provided by the Media Player framework. You’ll need to link to MediaPlayer.framework and import <MediaPlayer/MediaPlayer.h>.

Exploring the Music Library

Everything in the music library, as seen by your code, is an MPMediaEntity. This is an abstract class that endows its subclasses with the ability to describe themselves through key–value pairs called properties. (This use of the word “properties” has nothing to do with Objective-C properties, explained in Chapter 12; these properties are more like entries in an NSDictionary, except that the keys are not objects.) The repertoire of properties depends on the sort of entity you’re looking at; many of them will be intuitively familiar from your use of iTunes. For example, ...

Get Programming iOS 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.