我正在尝试使用9.3中的新Apple Music API将歌曲添加到我的应用程序创建的播放列表中,而不将其添加到用户的库中.
考虑产品ID 316654632,它是凤凰城的歌曲Lisztomania,位于美国iTunes Store.
使用以下代码,我可以播放这首歌
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController systemMusicPlayer];
[musicPlayer setQueueWithStoreIDs:@[@"316654632"]];
[musicPlayer play];
Run Code Online (Sandbox Code Playgroud)
使用以下代码,我可以将歌曲添加到Apple Music库中
[[MPMediaLibrary defaultMediaLibrary] addItemWithProductID:@"316654632" completionHandler:^(NSArray<__kindof MPMediaEntity *> * _Nonnull entities, NSError * _Nullable error) {
NSLog(@"%@", error);
}];
Run Code Online (Sandbox Code Playgroud)
错误是零,我可以在我的库中看到这首歌.
但尝试使用播放列表同样不起作用.
[[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);
}];
}
}];
Run Code Online (Sandbox Code Playgroud)
播放列表已创建,我可以在Music.app中看到它,但是当我尝试添加我播放并添加到我的库中的相同产品ID到播放列表时,我收到错误
Error Domain=MPErrorDomain Code=4 "The requested id could not be …