通过mpmediaitem获取ipod里的音乐文件。mpmediaitem可以获取它的url 但这个url跟路径是没有关系的,它都是ipod-library://item/item.mp3?id=-7350999950458851124这样的类型的。然后可以:
MPMediaQuery *query = [MPMediaQuery playlistsQuery];
NSArray *lists = [query items];
for (MPMediaItem *item in lists) {
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];//获取音乐路径 ipod-library://item/item.mp3?id=-7350999
NSLog(@"url = %@",url);
}
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url
error:nil];
[audioPlayer play];