Trying to use MPMediaPickerController to pass user-chosen song URL into AVAudioPlayer init. Code compiles but nothing plays. Is this even possible? Here's what I've got...
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
[self dismissModalViewControllerAnimated:YES];
if ([mediaItemCollection count] < 1) {
return;
}
//[song release];
song = [[mediaItemCollection items] objectAtIndex:0];
songLabel.hidden = NO;
artistLabel.hidden = NO;
imgButton.hidden = NO;
artwork = [song valueForProperty: MPMediaItemPropertyArtwork];
//coverArtView.hidden = NO;
songLabel.text = [song valueForProperty:MPMediaItemPropertyTitle];
artistLabel.text = [song valueForProperty:MPMediaItemPropertyArtist];
audioURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
audioDuration = [song valueForProperty:MPMediaItemPropertyPlaybackDuration];
audioBPM = [song valueForProperty:MPMediaItemPropertyBeatsPerMinute];
//Play audio
NSString *resourcePath = [NSString stringWithFormat:@"%@",[audioURL absoluteString]];
NSData *soundData = [NSData dataWithContentsOfURL:audioURL];
audioPlayer = [[AVAudioPlayer alloc] initWithData:soundData error: nil];
audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath isDirectory:FALSE] error:nil];
//audioPlayer.delegate = self; <<I'll have to resolve this for as of now, MPMediaController is delegate, not AVAudioPlayer
[audioPlayer prepareToPlay];
[audioPlayer setVolume: 1.0];
[audioPlayer setDelegate: self];
[audioPlayer play];
Many thanks