tasker: fix player main thread bugs on restore

This commit is contained in:
Alexander Capehart 2024-08-21 13:58:01 -06:00
parent 27e378ae2a
commit cc7f9ba539
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -164,17 +164,17 @@ class ExoPlaybackStateHolder(
logD("Restoring playback state") logD("Restoring playback state")
restoreScope.launch { restoreScope.launch {
val state = persistenceRepository.readState() val state = persistenceRepository.readState()
if (state != null) { withContext(Dispatchers.Main) {
// Apply the saved state on the main thread to prevent code expecting if (state != null) {
// state updates on the main thread from crashing. // Apply the saved state on the main thread to prevent code expecting
withContext(Dispatchers.Main) { // state updates on the main thread from crashing.
playbackManager.applySavedState(state, false) playbackManager.applySavedState(state, false)
if (action.play) { if (action.play) {
playbackManager.playing(true) playbackManager.playing(true)
} }
} else if (action.fallback != null) {
playbackManager.playDeferred(action.fallback)
} }
} else if (action.fallback != null) {
playbackManager.playDeferred(action.fallback)
} }
} }
} }