O'Reilly logo

Programming iOS 5, 2nd Edition 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 constitute the device’s music library; the user can play them with the Music app (formerly called the iPod app on some devices). iOS has provided the programmer with various forms of access to the device’s music library; you can:

  • Explore the music library
  • Play an item from the music library
  • Learn and control what the 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 the Objective-C properties discussed in Chapter 12; these properties are more like entries in an NSDictionary.) 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, a media item has a title, an album title, a track number, an artist, a composer, and so on; a playlist has a title, a flag indicating whether it is a “smart” playlist, and so ...

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