我很新于 iPhone 和 iOS 开发中的音频播放。我想在我的应用程序中从 iPod 图书馆播放歌曲。我已经在 Google 中尽力搜索了很多,但是我得到的答案是使用 iPod 图书馆,但我不知道如何从 iPod 图书馆中播放所选的歌曲。这是我在应用程序中使用的代码:
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.prompt = NSLocalizedString (@"Select songs to play", "Prompt in media item picker");
[self presentModalViewController:picker animated:YES];
[picker release];
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self dismissModalViewControllerAnimated: YES];
NSLog(@"MediaItemCollection : %@", mediaItemCollection);
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); // Here i retrieved all song titles.
}
}
请问有人能建议我如何从iPod音乐库播放歌曲吗?