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,20 +164,20 @@ class ExoPlaybackStateHolder(
logD("Restoring playback state") logD("Restoring playback state")
restoreScope.launch { restoreScope.launch {
val state = persistenceRepository.readState() val state = persistenceRepository.readState()
withContext(Dispatchers.Main) {
if (state != null) { if (state != null) {
// Apply the saved state on the main thread to prevent code expecting // Apply the saved state on the main thread to prevent code expecting
// state updates on the main thread from crashing. // state updates on the main thread from crashing.
withContext(Dispatchers.Main) {
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) { } else if (action.fallback != null) {
playbackManager.playDeferred(action.fallback) playbackManager.playDeferred(action.fallback)
} }
} }
} }
}
// Shuffle all -> Start new playback from all songs // Shuffle all -> Start new playback from all songs
is DeferredPlayback.ShuffleAll -> { is DeferredPlayback.ShuffleAll -> {
logD("Shuffling all tracks") logD("Shuffling all tracks")