【问题标题】:MPMusicPlayerController.systemMusicPlayer locks main thread with _establishConnectionIfNeeded on iOS 14.5MPMusicPlayerController.systemMusicPlayer 在 iOS 14.5 上使用 _establishConnectionIfNeeded 锁定主线程
【发布时间】:2021-05-03 18:31:56
【问题描述】:

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

[SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded 超时[ping 没有 pong]
[SDKPlayback] SYNC-WATCHDOG-1:尝试唤醒远程进程
[SDKPlayback] SYNC-WATCHDOG-2:断开连接

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

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

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

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

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

[core] "从守护进程返回的错误:Error Domain=com.apple.accounts Code=9 "(null)""
[默认] ACAccountStore 0x280fe13b0 - 检索 iTunesStore 帐户时出错。 err=错误域=com.apple.accounts 代码=9 "(null)"
[默认] ACAccountStore 0x280fe13b0 - 检索 iTunesStore 帐户时出错。 err=错误域=com.apple.accounts Code=9 "(null)"

但也有可能更具破坏性:

[默认] ACAccountStore 0x280fe13b0 - 检索本地商店帐户时出错。 err=错误域=com.apple.accounts 代码=9 "(null)"
[默认] [ICUserIdentityStore] 获取本地商店帐户失败,出现错误:Error Domain=com.apple.accounts Code=9 "(null)"

此代码在 iOS 14.5 之前有效。

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

【问题讨论】:

    标签: ios swift mpmusicplayercontroller


    【解决方案1】:

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

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

    【讨论】:

    • Apple 说“系统会在播放时自动调用此方法,但提前调用它可以最大限度地减少调用 play() 和开始声音输出之间的延迟”。在我的情况下,它是不需要的。
    • 是的(理论上),但我刚刚看到了这个看门狗错误,并通过明确说明解决了
    • 随着 iOS 14.8 再次出现问题,我尝试了这个建议但没有成功。
    【解决方案2】:

    升级到 iOS 14.5.1 修复了它。

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

    【讨论】:

    • 这太疯狂了!花了很多时间试图绕过它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2012-01-23
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    相关资源
    最近更新 更多