我有个超级奇怪的问题。我正在使用iOS13 MPMediaPickerController从用户那里获取一些苹果音乐库的歌曲,以便通过[MPMusicPlayerController applicationMusicPlayer]播放。
现在,我从一些播放列表中下载了一些未下载的歌曲,并将委托函数添加到我的库中。
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection报税
mediaItemCollection.items.firstObject不能由播放机播放的MPModelObjectMediaItem类型的对象。(我也不能投到那种类型,因为它是未知的。此外,也没有这种类型的文档。它似乎是mediaplayer框架中的一个私有类。)
我期待的是MPConcreteMediaItem类型,它是为所有下载的(以及所有不在播放列表中的其他云项目)传入的。
选择器配置如下
musicPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
musicPicker.showsCloudItems = true;
musicPicker.showsItemsWithProtectedAssets = true;
musicPicker.delegate = self;
musicPicker.allowsPickingMultipleItems = false;有什么建议吗?
发布于 2020-01-25 09:44:23
如果您没有将它们添加到您的音乐库中,那么加载到您自己的应用程序中的项目似乎就无法正确加载。(OS13.3)
我正在使用这个解决方法:
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
assert(mediaItemCollection.count == 1);
// this check is done because it seems that in the following scenario you dont get a
// MPConcreteMediaItem which can be played. Instead you get a MPModelObjectMediaItem
// this happens when an item was selected that is inside a playlist, but does not belong
// to your library (nor is it downloaded to your device)
if(mediaItemCollection.items.firstObject.persistentID <= 0)
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Song Not Added")
message:@"This song must be added to your Apple Music library. Please add the song to your library from the Music App."
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDefault
handler:nil]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Open Music App"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *alertAction)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"music://"]
options:nil
completionHandler:nil];
}]];
[self presentViewController:alertController animated:true completion:nil];
return;
}
// good to go? then load it
[musicPlayer setQueueWithItemCollection:mediaItemCollection];
...
}https://stackoverflow.com/questions/59903442
复制相似问题