MPMusicPlayerController.systemMusicPlayer 在 iOS 14.5 上使用 _establishConnectionIfNeeded 锁定主线程

MPMusicPlayerController.systemMusicPlayer locks main thread with _establishConnectionIfNeeded on iOS 14.5

一个应该播放音乐的应用程序现在锁定主线程并出现以下错误:

[SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded timeout [ping did not pong]
[SDKPlayback] SYNC-WATCHDOG-1: Attempting to wake up the remote process
[SDKPlayback] SYNC-WATCHDOG-2: Tearing down connection

按照 MPMusicPlayerController 文档中的要求使用了主线程。

这发生在 .play() 指令中:

private var musicPlayer = MPMusicPlayerController.systemMusicPlayer
// ....

musicPlayer.setQueue(with: selectedMediaItemCollection)
musicPlayer.shuffleMode = .songs
musicPlayer.repeatMode = .all
musicPlayer.play()

当应用程序启动时,即使我只请求访问本地音乐,这些错误也是可见的:

[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
[Default] ACAccountStore 0x280fe13b0 - Error retrieving iTunesStore accounts. err=Error Domain=com.apple.accounts Code=9 "(null)"
[Default] ACAccountStore 0x280fe13b0 - Error retrieving iTunesStore accounts. err=Error Domain=com.apple.accounts Code=9 "(null)"

不过还有一个可能危害更大:

[Default] ACAccountStore 0x280fe13b0 - Error retrieving local store account. err=Error Domain=com.apple.accounts Code=9 "(null)"
[Default] [ICUserIdentityStore] Failed to fetch local store account with error: Error Domain=com.apple.accounts Code=9 "(null)"

此代码在 iOS 14.5.

之前有效

有任何修复或解决方法的想法吗?

升级到 iOS 14.5.1 修复了它。

但是 iOS 14.8 时问题再次出现...我向 Apple 提交了 TSI。

我认为建议在执行play()命令之前调用prepareToPlay():

    musicPlayerController.prepareToPlay { (error) in
        if let e = error {
            print(e)
        }
        self.musicPlayerController.play()
    }