mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user