MPMusicPlayerController无法从Apple Music播放

时间:2019-09-25 22:23:39

标签: ios mpmusicplayercontroller apple-music apple-musickit

我正在尝试播放Apple Music中的歌曲,但出现以下日志失败:

2019-09-26 00:15:57.790999+0200 [1886:463973] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-09-26 00:15:57.791129+0200 [1886:463973] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-09-26 00:15:57.792655+0200 [1886:464074] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-09-26 00:15:57.792770+0200 [1886:464074] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-09-26 00:15:57.794124+0200 [1886:464074] SSAccountStore: Unable to get the local account. error = Error Domain=SSErrorDomain Code=100 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store}
2019-09-26 00:15:59.670842+0200 [1886:463973] [SDKPlayback] -[MPMusicPlayerController prependQueueDescriptor] completed id=applicationMusicPlayer error: Error Domain=MPCPlayerRequestErrorDomain Code=1 "No commands provided." UserInfo={NSDebugDescription=No commands provided.}
2019-09-26 00:15:59.671051+0200 [1886:463973] [SDKPlayback] -[MPMusicPlayerController prepareToPlay] completed id=applicationMusicPlayer error: Error Domain=MPMusicPlayerControllerErrorDomain Code=1 "prepareToPlay without a queue" UserInfo={NSDebugDescription=prepareToPlay without a queue}
2019-09-26 00:15:59.681627+0200 [1886:464074] [MediaRemote] MRC <MPCPlayerPath: route=<MPAVEndpointRoute: 0x282930a80 name=iPhone uid=LOCAL> origin=Nastasia's iPhone-1280262988 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}
2019-09-26 00:15:59.681787+0200 [1886:464074] [SDKPlayback] -[MPMusicPlayerController play] completed id=applicationMusicPlayer error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0" UserInfo={NSDebugDescription=Failed to send command 0, NSUnderlyingError=0x281319230 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1)" UserInfo={NSDebugDescription=Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=1}}}
2019-09-26 00:16:03.596320+0200 [1886:464071] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-09-26 00:16:03.596374+0200 [1886:464071] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-09-26 00:16:03.597965+0200 1886:464051] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-09-26 00:16:03.598079+0200 [1886:464051] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-09-26 00:16:03.599416+0200 [1886:464074] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-09-26 00:16:03.599456+0200 [1886:464074] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-09-26 00:16:03.599542+0200 [1886:464074] SSAccountStore: Unable to get the local account. error = Error Domain=SSErrorDomain Code=100 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store}

我还尝试了苹果公司的名为Adding-Content-to-Apple-Music的官方示例代码项目,并获得了类似的结果:


2019-09-25 23:20:37.268162+0200 [1738:432623] [RemoteControl] userIdentityForMediaRemoteOptions -❗️No user identity data. Using active account.
2019-09-25 23:20:37.333703+0200 [1738:432751] [SDKPlayback] -[MPMusicPlayerController prepareToPlayWithCompletionHandler:] completed id=applicationMusicPlayer error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 122" UserInfo={NSDebugDescription=Failed to send command 122, NSUnderlyingError=0x282eacff0 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 122 (MRMediaRemoteCommandHandlerStatus = 2)" UserInfo={NSDebugDescription=Failed to send command 122 (MRMediaRemoteCommandHandlerStatus = 2), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=2}}}
2019-09-25 23:20:37.333721+0200 [1738:432562] [SDKPlayback] -[MPMusicPlayerController prepareToPlay] completed id=applicationMusicPlayer error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 122" UserInfo={NSDebugDescription=Failed to send command 122, NSUnderlyingError=0x282eacff0 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 122 (MRMediaRemoteCommandHandlerStatus = 2)" UserInfo={NSDebugDescription=Failed to send command 122 (MRMediaRemoteCommandHandlerStatus = 2), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=2}}}
2019-09-25 23:20:37.337138+0200 [1738:432546] [MediaRemote] MRC <MPCPlayerPath: route=<MPAVEndpointRoute: 0x281498a80 name=iPhone uid=LOCAL> origin=Nastasia's iPhone-1280262988 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}
2019-09-25 23:20:37.337529+0200 [1738:432562] [SDKPlayback] -[MPMusicPlayerController play] completed id=applicationMusicPlayer error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0" UserInfo={NSDebugDescription=Failed to send command 0, NSUnderlyingError=0x282ead260 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1)" UserInfo={NSDebugDescription=Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=1}}}
2019-09-25 23:20:37.342424+0200 [1738:432623] [Middleware] INVALIDATE: 0x2813842d0: Invalidated before returning a response. Re-requesting items.
2019-09-25 23:20:38.144321+0200 [1738:432323] [SDKPlayback] Failed validators id=applicationMusicPlayer: {(
    play
)}
2019-09-25 23:20:38.944291+0200 [1738:432323] [SDKPlayback] Failed to get a valid response. Resetting expectations id=applicationMusicPlayer

有时候可以通过玩一些应用程序,去Apple Music应用程序,在其中播放某些东西,杀死它,再回来等等来随机解决此问题...

如果有人遇到过类似的问题,请让我知道如何解决。

在iOS 12和13,iPhone 6s和iPhone 11上发生,Apple Music帐户目前处于3个月的试用期。提供了所有音乐功能,能够成功获取开发者令牌和音乐用户令牌,两者都可以与Apple Music API请求正常工作。

1 个答案:

答案 0 :(得分:1)

似乎原因之一可能是我使用musicPlayerController.prepend()函数而不是setQueue()。不幸的是,由于音乐播放器的限制,我不得不使用prepend()

这是我的应用程序需要做的简短描述:

  • 用户开始播放歌曲列表。
  • 在播放期间,应用程序每5-10秒从后端获取一个新的歌曲列表,并将其设置为新的歌曲队列。这意味着通过接下来播放的内容它是非常动态的。

现在,在播放期间设置新队列时,setQueue()确实很糟糕。如果我仅呼叫setQueue(),那么什么也不会发生,那么旧队列将保留。但是,如果我在play()之后调用prepareToPlay()setQueue(),则当前播放将停止并且新队列的第一首歌曲将开始播放。那不是我想要的,我需要更改“幕后”队列,以便当用户在应用程序或iOS锁定屏幕中单击“跳到下一个”时,新的歌曲就会播放。这就是为什么我使用prepend()的原因-它可以正常工作,当前播放不会中断。另一种选择是-在applicationQueuePlayer上调用perform()时崩溃,并显示消息“花费时间太长”-我猜逐个手动删除30首歌曲的旧队列并不是最佳选择。

所以目前我只看到一个选项-手动存储一个状态,该状态将告诉您这是否是第一次运行。如果是,则呼叫setQueue(),否则呼叫prepend()。也没有办法让当前队列检查自己是否为空。

关于play()的问题-看起来似乎不那么简单。正如我上面已经提到的,如果我以前曾调用play()setQueue()会触发新的队列播放。这给我带来了更多的问题,因为当我在不使用setQueue()的情况下呼叫play()时,它什么也没做,但是每次我按下暂停/播放时,由于前者的播放,播放器跳到了下一首歌“无声” setQueue()。我不得不实现另一种变通方法,即调用player.currentPlaybackRate = 1而不是player.play(),这看起来不太好。如果所有这些都以某种方式记录在案,那就太好了。