O'Reilly logo

Programming iOS 4 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required