gpt4 book ai didi

ios - MPMediaPickerController didPickMediaItems 返回 MPModelObjectMediaItem

转载 作者:行者123 更新时间:2023-11-29 05:08:39 26 4
gpt4 key购买 nike

我遇到了一个非常奇怪的问题。我正在使用 iOS13 MPMediaPickerController 从用户苹果音乐库中获取一些歌曲,以便通过 [MPMusicPlayerController applicationMusicPlayer] 播放它。

现在,我已将一些播放列表中的一些未下载的歌曲添加到我的库中,委托(delegate)功能

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection

返回

mediaItemCollection.items.firstObject

播放器无法播放的 MPModelObjectMediaItem 类型的对象。 (我也不能转换为该类型,因为它是未知的。而且没有关于该类型的文档。它似乎是媒体播放器框架内的私有(private)类。)

我期待所有下载的类型(以及不在播放列表中的所有其他云项目)传入的类型 MPConcreteMediaItem

选择器的配置如下

musicPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
musicPicker.showsCloudItems = true;
musicPicker.showsItemsWithProtectedAssets = true;
musicPicker.delegate = self;
musicPicker.allowsPickingMultipleItems = false;

有什么提示吗?

最佳答案

嗯,如果您尚未将加载到自己的应用程序中的项目添加到您的音乐库中,则它们似乎无法正确加载。 (iOS13.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];
...
}

关于ios - MPMediaPickerController didPickMediaItems 返回 MPModelObjectMediaItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59903442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com