方法一:
MPMediaQuery *mysongsQuery = [MPMediaQuery songsQuery];
_songsArray = [mysongsQuery items];
for (MPMediaItem *song in _songsArray) {
NSString *songTitle = [song valueForProperty:MPMediaItemPropertyTitle];
NSString *assetUrl = [song valueForProperty:MPMediaItemPropertyAssetURL];
NSLog (@"%@ %@", songTitle,assetUrl);
}
MPMediaQuery *playlistQuery = [MPMediaQuery playlistsQuery];
for (MPMediaPlaylist *playlist in playlistQuery.items)
{
NSString *playlistName = [playlist valueForProperty:MPMediaPlaylistPropertyName];
NSLog (@"%@", playlistName);
}
MPMediaQuery *albumQuery = [MPMediaQuery albumsQuery];
方法二:
MPMediaPickerController *vc = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
vc.delegate = self;
[self presentViewController:vc animated:YES completion:^{
}];
并实现代理方法:
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection*)mediaItemCollection
{
MPMediaItem *item = mediaItemCollection.items.firstObject;
NSString *songTitle = [item valueForProperty:MPMediaItemPropertyTitle];
NSURL *assetUrl = [item valueForProperty:MPMediaItemPropertyAssetURL];
NSLog (@"%@ %@", songTitle,assetUrl);
[mediaPicker dismissViewControllerAnimated:YES completion:^{
}];
MPMusicPlayerController* mDRMAudioPlayer = [MPMusicPlayerController applicationMusicPlayer];
[mDRMAudioPlayer setQueueWithItemCollection:mediaItemCollection];
[mDRMAudioPlayer play];
}
- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker
{
[mediaPicker dismissViewControllerAnimated:YES completion:^{
}];
}
iOS上获取iTunes音乐权限,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/zengyanzhi/p/3861062.html