How to play the iPod Library file in the AVPlayer

user237708 picture user237708 · Dec 23, 2009 · Viewed 10.4k times · Source

How can I get an ipod library music file into AVAudioPlayer?

Answer

Steve Tranby picture Steve Tranby · Aug 22, 2010

As David mentions there is more work to do than this, for example you have to manage playing the next track in a collection of media items, but here is one way to do it with a set of MPMediaItems that a user selected from the iPod Picker. The AssetURL is what you use, it gives you a path to the MP3 file (e.g. ipod-library://item/item.mp3?id=-6889145242935454020)

NSURL *anUrl = [[mediaItems objectAtIndex: 0] valueForProperty:MPMediaItemPropertyAssetURL];
self.audioPlayerMusic = [[[AVPlayer alloc] initWithURL:anUrl] retain];                      
[self.audioPlayerMusic play];