MPNowPlayingInfoCenter not responding - app freezes

I have an issue with updating MPNowPlayingInfoCenter when trying to read nowPlayingInfo I don't get a response leading to blocking the current thread indefinitely. I'm updating MPNowPlayingInfoCenter on main thread which results in an app freeze.

func staticUpdate() {

    logger.log(.debug, "start static update")

    infoCenter.nowPlayingInfo = nowPlayingInfo

    logger.log(.debug, "end static update")

}

func dynamicUpdate() {

    logger.log(.debug, "start update - read")

    var mpInfo = infoCenter.nowPlayingInfo ?? [String: Any]()

    logger.log(.debug, "start update - write")

    ...

    infoCenter.nowPlayingInfo = mpInfo

    logger.log(.debug, "end update")
}
/*
2022-04-25 09:28:19.051435+0200 [Debug] [main] [NowPlayingInfoCenterController.swift:128] start static update
2022-04-25 09:28:19.051834+0200 [Debug] [main] [NowPlayingInfoCenterController.swift:130] end static update
2022-04-25 09:28:19.052251+0200 [Debug] [main] [NowPlayingInfoCenterController.swift:186] start update - read
*/

I'm overwriting nowPlayingInfo when media changes, then I'm updating it on any status changes (progress, status,...) (see timestamps, we read ~1ms after write but never reach infoCenter.nowPlayingInfo = mpInfo)

Questions:

  • shouldn't infoCenter.nowPlayingInfo always be readable?
  • can I update infoCenter from any queue? (this would solve only app freeze..)
  • the only workaround I've found was not to read nowPlayingInfo, but only write to it. keeping it's state locally stored

Add a Comment