views:

801

answers:

5

Hi, I need your help Please tell me how you taken the ipod library music file in the AVAudioPlayer?

Thanks, Karthick

+3  A: 

The SDK has no provision for reading files from the iPod library (as you'd need to do to use AVAudioPlayer with it), probably for anti-piracy reasons. To play iPod library items, use the MPMusicPlayerController class.

Noah Witherspoon
A: 

Here's a link to Apple's documentation:

http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPMusicPlayerController%5FClassReference/Reference/Reference.html

As Noah Witherspoon indicated, you can't use AVAudioPlayer to do this.

Frank Schmitt
A: 

Is there any possibility to get information about dB-metering in MPMusicPlayerController? Perhaps initiating an AVAudioSession for Recording in parallel would do the job?? I need dB-values to build some kind of volume-spectrograph.

L'g
A: 

Yes, you can play songs from the iPod library using the SDK without resorting to the MPMusicPlayerController class.

The more basic AVPlayer class can handle audio files from the iPod library by using the NSUrl value from the song's MPMediaItemPropertyAssetURL property. You have to do a lot more work to get everything setup properly, but it can be done.

David Patierno
+1  A: 

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];
Steve Tranby