The Music Player
The Media Player framework class for playing an MPMediaItem is MPMusicPlayerController. It comes in two flavors, depending on which class method you use to get an instance:
-
applicationMusicPlayer
-
Plays an MPMediaItem from the music library within your application. The song being played by the
applicationMusicPlayer
can be different from the Music app’s current song. This player stops when your app is not in the foreground. -
iPodMusicPlayer
- The global music player — the very same player used by the Music app. This might already be playing an item, or might be paused with a current item, at any time while your app runs; you can learn or change what item this is. The global music player continues playing independently of the state of your app, and the user can at any time alter what it is doing.
Warning
An applicationMusicPlayer
is not really inside your app. It is actually the global music player behaving differently. It has its own audio session. You cannot play its audio when your app is in the background. You cannot make it the target of remote control events. If these limitations prove troublesome, use the iPodMusicPlayer
(or AVPlayer, discussed later in this chapter).
A music player doesn’t merely play an item; it plays from a queue of items. This behavior is familiar from iTunes and the Music app. For example, in iTunes, when you switch to a playlist and double-click the first song to start playing, when iTunes comes to the end of that song, it proceeds by default ...
Get Programming iOS 6, 3rd Edition 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.