From bff16e0dd1fc681d7874d8952b6d04db77e3e2e8 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Sat, 26 Sep 2026 21:25:33 +0000 Subject: [PATCH] consume a finished queued track without reloading the window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Advancing naturally out of an up-next track rebuilt the whole window, which reset the already-playing next track back to its start — audible as the first second repeating. Remove the finished item from the player in place (as the context edit path already does) and recentre instead, so the current item and its prepared source survive. Regression test asserts no setWindow on a natural advance out of a queued track. --- .../subtracks/playback/PlaybackController.kt | 12 +++++++- .../playback/PlaybackControllerTest.kt | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) 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)