Reset queue index on end
Some checks are pending
App / Build / Build (push) Waiting to run
App / Lint / Lint (push) Waiting to run
App / Test / Test (push) Waiting to run
Gradle / Validate wrapper / Validate (push) Waiting to run
Repo / Label merge conflict / Triage (push) Waiting to run

With this change the queue index will always reset to -1 (INDEX_NONE) once the last item in the queue ends instead of leaving the last queue item active. This solves various issues in the UI (like the screensaver) where it keeps showing the last item when nothing is playing
This commit is contained in:
Niels van Velzen 2024-11-16 20:01:26 +01:00 committed by Niels van Velzen
parent ee1403aaad
commit 300346feb8

View File

@ -54,7 +54,8 @@ class QueueService internal constructor() : PlayerService(), Queue {
override fun onVideoSizeChange(width: Int, height: Int) = Unit override fun onVideoSizeChange(width: Int, height: Int) = Unit
override fun onMediaStreamEnd(mediaStream: PlayableMediaStream) { override fun onMediaStreamEnd(mediaStream: PlayableMediaStream) {
coroutineScope.launch { coroutineScope.launch {
next(usePlaybackOrder = true, useRepeatMode = true) val nextItem = next(usePlaybackOrder = true, useRepeatMode = true)
if (nextItem == null && _entryIndex.value != Queue.INDEX_NONE) setIndex(Queue.INDEX_NONE, true)
} }
} }
}) })
@ -91,7 +92,7 @@ class QueueService internal constructor() : PlayerService(), Queue {
} }
// Return item or null if not found // Return item or null if not found
return if (index < fetchedItems.size) fetchedItems[index] return if (index >= 0 && index < fetchedItems.size) fetchedItems[index]
else null else null
} }
@ -144,7 +145,7 @@ class QueueService internal constructor() : PlayerService(), Queue {
} }
override suspend fun setIndex(index: Int, saveHistory: Boolean): QueueEntry? { override suspend fun setIndex(index: Int, saveHistory: Boolean): QueueEntry? {
if (index < 0) return null if (index < 0 && index != Queue.INDEX_NONE) return null
// Save previous index // Save previous index
if (saveHistory && _entryIndex.value != Queue.INDEX_NONE) { if (saveHistory && _entryIndex.value != Queue.INDEX_NONE) {