persist and restore the playback position within the track

This commit is contained in:
austinried
2026-10-04 00:29:55 +00:00
parent 89376cef86
commit 20ab30920f
8 changed files with 884 additions and 5 deletions
@@ -70,6 +70,7 @@ class FakePlayerHandle : PlayerHandle {
this.items.clear()
this.items += items
index = startIndex
positionMs = startPositionMs
idle = true
ended = false
buffering = false
@@ -905,6 +905,33 @@ class PlaybackControllerTest {
assertTrue(controller.state.value.shuffle)
}
@Test
fun restoringResumesFromTheSavedPosition() {
seedAlbum(3, sourceId = 1)
controller.playAlbum(1, "al1", 0)
await {
controller.state.value.item
?.id == "s1"
}
runBlocking { queues.setPosition(12_000L) }
val restoredHandle = FakePlayerHandle()
val restored = PlaybackController(sources, queues, FakePlayerConnection(restoredHandle), dispatcher = dispatcher)
restored.connect()
await {
restored.state.value.item
?.id == "s1"
}
assertEquals(12_000L, restored.state.value.positionMs)
assertEquals(
"setWindow(size=3, start=0, position=12000)",
restoredHandle.operations.first { it.startsWith("setWindow") },
)
restored.close()
}
private fun seedAlbum(
count: Int,
sourceId: Long,