2
我正在編程獲取iPhone音樂庫以顯示,用戶選擇一首歌曲,然後這首歌曲標題反映在UILabel
中。如果只是這麼簡單!我試圖將MPMediaItem
變成NSString
,然後UILabel
反映了這一點,但我只是得到(空)返回!爲什麼從MPMediaPicker(iOS)返回(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];
}
在此先感謝
+1這是一個了不起的幫助,謝謝!我在寫這篇文章後不久就注意到了錯誤的代表設置。再一次,謝謝你! – iphoneapplelover123
很高興幫助!如果您滿意,請接受答案。謝謝! –