prepare the restored track so the first play is instant

Restore set the window with autoplay = false and never prepared, so the first tap paid
for the connection, the first range request and the startup buffer. Prepare once the
window is set; toggling play then only starts playback.
This commit is contained in:
austinried
2026-10-04 00:30:00 +00:00
parent ea09f24844
commit 3bcf87b5b4
2 changed files with 5 additions and 2 deletions
@@ -662,6 +662,7 @@ class PlaybackController(
val position = queueRepository.cursor().coerceIn(0, snapshot.size - 1)
lastSavedPositionMs = queueRepository.cursorPositionMs().coerceAtLeast(0)
loadWindow(position, autoplay = false, startPositionMs = lastSavedPositionMs)
player?.prepare()
}
private suspend fun stop() = startLock.withLock { stopLocked() }
@@ -144,18 +144,20 @@ class PlaybackControllerTest {
}
@Test
fun togglingPlayOnARestoredQueuePreparesBeforePlaying() {
fun aRestoredQueueIsPreparedBeforeTheFirstPlay() {
seedAlbum(5, sourceId = 1)
runBlocking { queues.replace(listOf(queues.albumEntry(1, "al1"))) }
controller.connect()
await { handle.items.isNotEmpty() }
await { handle.operations.contains("prepare") }
handle.operations.clear()
controller.togglePlayPause()
await { handle.operations.contains("play") }
assertEquals(listOf("prepare", "play"), handle.operations)
assertEquals(listOf("play"), handle.operations)
}
@Test