iOS上获取iTunes音乐权限
方法一:
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:^{
}];
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。