以下代码检索iPhone中的所有歌曲,但我想检索数组中的所有歌曲。我的意思是我可以在阵列中拥有歌曲名称的数组吗?如果是的话,怎么做?
谢谢 -
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (@"Add songs to play", "Prompt in media item picker");
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated: YES];
[self presentModalViewController: picker animated: YES];
[picker release];
答案 0 :(得分:2)
请参阅iPod Library Access Programming Guide。在其中有一个示例向您显示与整个库匹配的媒体查询,该库允许您将其放入数组中:
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSLog(@"Logging items from a generic query...");
NSArray *itemsFromGenericQuery = [everything items];
for (MPMediaItem *song in itemsFromGenericQuery) {
NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];
NSLog(@"%@", songTitle);
}