Hi, I need your help Please tell me how you taken the ipod library music file in the AVAudioPlayer?
Thanks, Karthick
Hi, I need your help Please tell me how you taken the ipod library music file in the AVAudioPlayer?
Thanks, Karthick
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.
Here's a link to Apple's documentation:
As Noah Witherspoon indicated, you can't use AVAudioPlayer to do this.
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.
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.
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];