diff --git a/app/src/main/kotlin/com/subtracks/playback/PlaybackController.kt b/app/src/main/kotlin/com/subtracks/playback/PlaybackController.kt index 4f228c17..4387d341 100644 --- a/app/src/main/kotlin/com/subtracks/playback/PlaybackController.kt +++ b/app/src/main/kotlin/com/subtracks/playback/PlaybackController.kt @@ -554,7 +554,17 @@ class PlaybackController( endedHandled = false val next = if (position < updated.size) position else 0L queueRepository.setCursor(next) - loadWindow(next, autoplay = true) + val player = player + if (next == position && player != null && position - windowStart in 0 until player.itemCount) { + updating = true + player.removeAt((position - windowStart).toInt()) + updating = false + windowEnd-- + shiftWindowLocked(next) + refresh(next) + } else { + loadWindow(next, autoplay = true) + } } fun previous() { diff --git a/app/src/test/kotlin/com/subtracks/playback/PlaybackControllerTest.kt b/app/src/test/kotlin/com/subtracks/playback/PlaybackControllerTest.kt index e7a9c08a..21c5135f 100644 --- a/app/src/test/kotlin/com/subtracks/playback/PlaybackControllerTest.kt +++ b/app/src/test/kotlin/com/subtracks/playback/PlaybackControllerTest.kt @@ -823,6 +823,34 @@ class PlaybackControllerTest { eager.close() } + @Test + fun naturallyAdvancingOutOfAQueuedTrackDoesNotReloadTheWindow() { + seedAlbum(3, sourceId = 1) + seedSong("x1", "al2") + + controller.playAlbum(1, "al1", 0) + await { + controller.state.value.item + ?.id == "s1" + } + controller.addToQueue(1, QueueKind.Song, "x1") + await { runBlocking { controller.upcomingItem()?.id } == "x1" } + controller.next() + await { + controller.state.value.item + ?.id == "x1" + } + + handle.operations.clear() + handle.advanceTo(handle.currentIndex + 1) + await { + controller.state.value.item + ?.id == "s2" + } + + assertFalse(handle.operations.any { it.startsWith("setWindow") }) + } + @Test fun nextFollowsTheReorderedQueue() { seedAlbum(3, sourceId = 1)