- (void)viewDidLoad
{
[super viewDidLoad];
MPMediaPickerController *picker =[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt =@"Add songs to play";
[self presentModalViewController:picker animated: YES];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
NSLog(@"sdfadsf");
NSLog(@"%@",mediaItemCollection);
NSArray *slist=[mediaItemCollection copy];
NSLog(@"%@",slist);
}
答案 0 :(得分:0)
答案 1 :(得分:0)
您是否在.h?
中声明了MPMediaPickerControllerDelegate例如:
@interface FirstViewController:UIViewController
如果不这样可以解释为什么该方法没有触发。另外,我不相信它会在模拟器上运行;只在设备上。
编辑:
-(IBAction)presentLibrary:(id)sender
{
//this is called from a button press, but you could do it in viewDidLoad
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");
[self presentModalViewController: picker animated: YES];
}
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
NSLog(@"didpick");
if (mediaItemCollection) {
[_mediaPlayer setQueueWithItemCollection: mediaItemCollection];
_mediaCollection = mediaItemCollection;
}
[mediaPicker dismissModalViewControllerAnimated:YES];
}