How can I detect when my app goes from background to suspended state? or better about to be suspended..
AppDelegate has method for entering background and there's even a Notification for this, but I can't find anything about suspended.
And I guess receiveMemoryWarning is not the right one.
Post
Replies
Boosts
Views
Activity
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..)
Docs say: "For serial tasks, set the target of your serial queue to one of the global concurrent queues"
but how exactly?
DispatchQueue(label: "", target: .global(qos: .background))
// or
DispatchQueue(label: "", qos: .background, target: .global(qos: .background))
or is it the same?
context:
We use quite a few serial queues in our app. In general each service (e.g. analytics, downloading, etc) has it's own serial queue to sync. access to it's resources.
When connection is cut before track is fully buffered and player reaches end of loaded time ranges, audio stops but status is not updated:
elapsed Time continues to send events
player.timeControlStatus = playing
currentItem!.isPlaybackLikelyToKeepUp = true
player.status = readyToPlay
player.currentItem!.status = readyToPlay
currentItem!.isPlaybackLikelyToKeepUp = true
But an event is logged in errorLog()
"NSURLErrorDomain"
errorStatusCode -1009
This results in weird behaviour where a progress bar is continuing to show progress without any sound. It even continues beyond the total track duration.
Reproducible on demo app https://github.com/timstudt/PlayerApp:
start playback
let buffer til e.g. 70sec (loadedTimeRanges)
activate flight mode
seek to 60sec (returns = successful)
watch:
when player reaches 70sec mark, audio stops, but elapsed time continues.
Note: w/o seeking the player stalls correctly on 70sec mark.