From b53a96f574cf7c35b689c263a5305421b3d93bc2 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Sun, 21 Jan 2024 19:33:49 -0700 Subject: [PATCH] playback: fix crash when song cannot be restored The index is -1, which is not a valid position to seek through normally. In this case we should just ignore it. --- .../playback/state/PlaybackStateManager.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt index 2eacddff5..aa9ca0078 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt @@ -774,18 +774,21 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager { index }) - val oldStateMirror = stateMirror - - if (oldStateMirror.rawQueue != rawQueue) { - logD("Queue changed, must reload player") - stateHolder?.applySavedState(parent, rawQueue, StateAck.NewPlayback) - stateHolder?.playing(false) - } + if (index > -1) { + // Valid state where something needs to be played, direct the stateholder to apply + // this new state. + val oldStateMirror = stateMirror + if (oldStateMirror.rawQueue != rawQueue) { + logD("Queue changed, must reload player") + stateHolder?.applySavedState(parent, rawQueue, StateAck.NewPlayback) + stateHolder?.playing(false) + } - if (oldStateMirror.progression.calculateElapsedPositionMs() != savedState.positionMs) { - logD("Seeking to saved position ${savedState.positionMs}ms") - stateHolder?.seekTo(savedState.positionMs) - stateHolder?.playing(false) + if (oldStateMirror.progression.calculateElapsedPositionMs() != savedState.positionMs) { + logD("Seeking to saved position ${savedState.positionMs}ms") + stateHolder?.seekTo(savedState.positionMs) + stateHolder?.playing(false) + } } isInitialized = true