- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 9.3 中的新 Apple Music API 将歌曲添加到我的应用程序创建的播放列表中,而不是将其添加到用户的音乐库中。
考虑产品 ID 316654632,它是美国 iTunes Store 中 Phoenix 的歌曲 Lisztomania。
使用下面的代码,我可以播放歌曲
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController systemMusicPlayer];
[musicPlayer setQueueWithStoreIDs:@[@"316654632"]];
[musicPlayer play];
使用以下代码,我可以将歌曲添加到我的 Apple Music 音乐库
[[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, NSError * _Nullable error) {
NSLog(@"%@", error);
if (!error) {
[playlist addItemWithProductID:@"316654632" completionHandler:^(NSError * _Nullable error) {
NSLog(@"%@", error);
}];
}
}];
播放列表已创建,我可以在 Music.app 中看到它,但是当我尝试将我播放并添加到我的库中的相同产品 ID 添加到播放列表时,出现错误
Error Domain=MPErrorDomain Code=4“找不到请求的 ID”UserInfo={NSLocalizedDescription=找不到请求的 ID}
但如果我成功将相同的项目添加到我的图书馆,怎么会找不到呢?
好消息! Apple 已在 10.2.1 上修复了 rdar://26408683!
最佳答案
在我的播放列表转换应用程序 ( mixlib ) 中,我发现将一些轨道可靠地添加到新创建的播放列表的唯一解决方案是等待。
在我的测试中,等待五秒钟似乎就足够了。
[[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)), ^() {
[playlist addItemWithProductID:@"316654632" completionHandler:^(NSError * _Nullable error) {
NSLog(@"%@", error);
}];
}
}];
我怀疑这是与服务器/网络相关的问题,因为它有时无需等待即可运行。未找到的“请求的 ID”可能是播放列表 ID,而不是轨道 ID。
当它开始为播放列表工作时,它将一直有效。因此,您无需在添加每个附加轨道之前等待,而只需在添加第一个轨道之前等待。
关于ios - 使用时出错 -[MPMediaPlaylist addItemWithProductID :completionHandler:],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36902854/
当我在 Debug模式下在 iPhone 模拟器中进行身份验证时,将运行下面代码中的第一个 if 语句。但是,当我在安装了 Evernote 客户端的 iPhone 上进行调试时,if 语句未被评估。
在我使用 URLSession.dataTask(with:completionHandler:) 创建新的 session 数据任务之后并通过调用其 resume() 来启动任务方法,鉴于应用程序在
我是今天扩展的新手,我收到了这个警告,有人知道如何匹配可选要求吗? Instance method 'widgetPerformUpdate(completionHandler:)' nearly m
我想了解 NSObject 可能属于哪个类(除 NSAlert、NSOpenPanel 和 NSSavePanel 之外),以便响应上述调用(如问题标题中所示)。这是我需要做的场景。菜单选择的操作必须
我在互联网上到处搜索,但无法真正处理我找到的答案。因此,如果有人可以在这里帮助我,我将不胜感激。 我写了一个看起来像这样的函数: func setImage(imageName: String, co
为什么我的完成处理程序出现问题,我该如何解决? func loadImageusingCacheWithUrlString(urlString: String) { self.image =
我试图将 bool 值传递给我的完成处理程序。当应用程序运行时,将 bool 传递给我的完成处理程序的结果决定了我显示的警报。如果我在错误检查中调用它,应用程序会崩溃/锁定。如果我在其他任何地方调用它
所以我试图让它在完成处理程序之后做一些事情,但我一直收到错误: expected CLGeocodeCompletionHandler class func didCompleteGeocoding(
我想为我的 completionHandler 默认参数传递: func firstFunc(completionHandler: ((array:[String:AnyObject] = [:])
我最近加入了一个新项目并开始研究 iOS 应用程序代码库。但是,在最新的 Xcode 10 中,代码不再编译。 protocol NetworkClientType { associatedtyp
以下代码是线程安全的吗?如果是这样,如何保证ByteBuffer 的安全发布?执行 CompletionHandler 的线程的实例? AsynchronousSocketChannel channe
This question already has answers here: Swift 3 URLSession.shared() Ambiguous reference to member 'd
在 Xcode 5.0.2 中设置要显示为模式表的 NSAlert 对象时,我遇到了一个有趣的惊喜。 我计划使用 beginSheetModalForWindow:modalDelegate:didE
我已经执行了代码,但收到completionHandler 错误 如果没有更多上下文,表达类型不明确 据我了解,这是由于completionHandler 不匹配造成的。如何为completionHa
我正在使用 AVAssetImageGenerator 从影片剪辑中获取图像,而无需先播放它。现在我有一个问题如何在处理程序的循环中设置变量?是否可以?我收到此错误消息,但不知道这意味着什么。 (谷歌
我已经执行了代码,但收到completionHandler 错误 如果没有更多上下文,表达类型不明确 据我了解,这是由于completionHandler 不匹配造成的。如何为completionHa
我试图在加载数据后加载我的 CollectionView,但我不知道应该如何使用 CompletionHandler 来执行此操作。感谢帮助我的代码如下:用于获取数据: func GETData(){
我正在尝试使用 openActiveSessionWithPublishPermissions 在 Facebook 上发布消息,因此如果用户未登录,他需要先登录,然后使用 io6 Facebook
我有以下方法,如果 SessionStatus 完成,我想返回 movieDestinationUrl,但是我不断收到此错误 Unexpected non-void return value in v
我有一个 UITextField,它允许用户为 Facebook 照片输入自定义相册名称。 textFieldShouldReturn 后,我将 textField.text 发送到 Facebook
我是一名优秀的程序员,十分优秀!