我正在编程让 iPhone 音乐库显示,用户选择一首歌曲,然后这首歌的标题反映在UILabel
. 要是这么简单就好了!我已经尝试MPMediaItem
进入一个NSString
然后UILabel
反映这一点,但我只是得到(null)返回!
- (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];
}
提前致谢