大佬教程收集整理的这篇文章主要介绍了ios – 使用时出错 – [MPMediaPlaylist addItemWithProductID:completionHandler:],大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
考虑产品ID 316654632,它是凤凰城的歌曲Lisztomania,位于美国iTunes Store.
使用以下代码,我可以播放这首歌
@H_190_11@mPMusicPlayerController *musicPlayer = [MPMusicPlayerController sy@L_929_4@musicPlayer]; [musicPlayer setQueueWithStorEIDs:@[@"316654632"]]; [musicPlayer play];
[[MPMediaLibrary defaultMediaLibrary] addItemWithProductID:@"316654632" completionHandler:^(NSArray<__kindof MPMediaEntity *> * _Nonnull entities,NSError * _Nullable error) { NSLog(@"%@",error); }];
错误是零,我可以在我的库中看到这首歌.
但尝试使用播放列表同样不起作用.
[[MPMediaLibrary defaultMediaLibrary] getPlaylistWithUUID:uuid creationMetadata:[[MPMediaPlaylistCreationMetadata alloc] initWithName:@"Test Playlist"] completionHandler:^(MPMediaPlaylist * _Nullable playlist,error); if (!error) { ; } }];
播放列表已创建,我可以在Music.app中看到它,但是当我尝试添加相同的产品ID时,我播放了&添加到我的库到播放列表,我收到一个错误
错误域= MPErrorDomain代码= 4“无法找到请求的ID”UserInfo = {NSLocalizedDescription =找不到请求的ID}
但如果我成功将相同的项目添加到我的库中,怎么可能找不到呢?
好消息! Apple在10.2.1修复了rdar:// 26408683!
在我的测试中,等待五秒似乎就足够了.
[[MPMediaLibrary defaultMediaLibrary] getPlaylistWithUUID:uuid creationMetadata:[[MPMediaPlaylistCreationMetadata alloc] initWithName:@"Test Playlist"] completionHandler:^(MPMediaPlaylist * _Nullable playlist,NSError * _Nullable error) { if (!error) { dispatch_after(dispatch_time(DISPATCH_TIME_Now,5 /*seconds*/ * NSEC_PER_SEC),dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)),^() { ; } }];
我怀疑它是服务器/网络相关的问题,因为它有时无需等待.未找到的“请求的id”可以是播放列表id,而不是轨道id.
以上是大佬教程为你收集整理的ios – 使用时出错 – [MPMediaPlaylist addItemWithProductID:completionHandler:]全部内容,希望文章能够帮你解决ios – 使用时出错 – [MPMediaPlaylist addItemWithProductID:completionHandler:]所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。