I am programming to get the iPhone music library to display, the user selects a song, then this song title is reflected in a UILabel. If only it was that simple! I have tried getting the MPMediaItem into a NSString then the UILabel reflecting this, but i’m just getting (null) returned!
- (IBAction)showMediaPicker:(id)sender {
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
//mediaPicker.allowsPickingMultipleItems = YES;
mediaPicker.prompt = @"Select Your Favourite Song!";
[self presentModalViewController:mediaPicker animated:YES];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItem *) mediaItemCollection {
NSString *titleString = [mediaItemCollection valueForProperty:MPMediaItemPropertyTitle];
titleLabel.text = [NSString stringWithFormat:@"Title: %@",titleString];
[self dismissModalViewControllerAnimated: YES];
}
Thanks in advance
You’re trying to grab the title for a mediaItemCollection. You need to get the individual song title like this:
Also by the way, you have the wrong delegate setup for your MPMediaPickerControllerDelegate:
It should be:
-You have the MPMediaItemCollection as just an MPMediaItem