Skip to content

Commit

Permalink
playback: fix crash when song cannot be restored
Browse files Browse the repository at this point in the history
The index is -1, which is not a valid position to seek through
normally. In this case we should just ignore it.
  • Loading branch information
OxygenCobalt committed Jan 22, 2024
1 parent 588b6e9 commit b53a96f
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b53a96f

Please sign in to comment.