播放(非库)Apple Music内容-请求失败

时间:2019-06-20 15:23:27

标签: ios swift mpmusicplayercontroller mpmediaquery apple-musickit

我正在尝试使用以下代码播放专辑...

let predicate = MPMediaPropertyPredicate(value: "1459938538", forProperty: MPMediaItemPropertyAlbumPersistentID)
let iCloudPredicate = MPMediaPropertyPredicate(value: true, forProperty: MPMediaItemPropertyIsCloudItem)
let query = MPMediaQuery.albums()
query.filterPredicates = [predicate, iCloudPredicate]

let mp = MPMusicPlayerController.applicationMusicPlayer
mp.setQueue(with: query)
mp.play()

但是失败了

  

[SDKPlayback] -[MPMusicPlayerController prepareToPlay] timeout

     

[MediaRemote] MRC <MPCPlayerPath: route=<MPAVEndpointRoute: 0x280f1a280 name=iPhone uid=LOCAL> origin=iPhoneID bundleID=com.apple.MediaPlayer.RemotePlayerService playerID=MPMusicPlayerApplicationController>: Undo optimistic state [failed] command=Play error=Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1)" UserInfo={NSDebugDescription=Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=1}

     

[SDKPlayback] -[MPMusicPlayerController play] completed error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0" UserInfo={NSDebugDescription=Failed to send command 0, NSUnderlyingError=0x28344c810 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1)" UserInfo={NSDebugDescription=Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=1}}}

••如果删除谓词,它将可以播放本地专辑。

SKCloudServiceController.requestAuthorization.authorized

•该设备同时具有.musicCatalogPlayback.addToCloudMusicLibrary功能。

1459938538似乎是有效的ID(用于最新的麦当娜专辑-https://music.apple.com/gb/album/madame-x-deluxe/1459938538

是否有任何关于如何播放不在我的音乐库中的专辑的提示?

1 个答案:

答案 0 :(得分:1)

MPMediaQuery仅用于库项目。您需要使用网络Apple Music搜索API来获取商店ID,以用于设置队列。