mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 15:29:15 +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)
|
val position = queueRepository.cursor().coerceIn(0, snapshot.size - 1)
|
||||||
lastSavedPositionMs = queueRepository.cursorPositionMs().coerceAtLeast(0)
|
lastSavedPositionMs = queueRepository.cursorPositionMs().coerceAtLeast(0)
|
||||||
loadWindow(position, autoplay = false, startPositionMs = lastSavedPositionMs)
|
loadWindow(position, autoplay = false, startPositionMs = lastSavedPositionMs)
|
||||||
|
player?.prepare()
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun stop() = startLock.withLock { stopLocked() }
|
private suspend fun stop() = startLock.withLock { stopLocked() }
|
||||||
|
|||||||
@@ -144,18 +144,20 @@ class PlaybackControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun togglingPlayOnARestoredQueuePreparesBeforePlaying() {
|
fun aRestoredQueueIsPreparedBeforeTheFirstPlay() {
|
||||||
seedAlbum(5, sourceId = 1)
|
seedAlbum(5, sourceId = 1)
|
||||||
runBlocking { queues.replace(listOf(queues.albumEntry(1, "al1"))) }
|
runBlocking { queues.replace(listOf(queues.albumEntry(1, "al1"))) }
|
||||||
|
|
||||||
controller.connect()
|
controller.connect()
|
||||||
await { handle.items.isNotEmpty() }
|
await { handle.items.isNotEmpty() }
|
||||||
|
await { handle.operations.contains("prepare") }
|
||||||
|
|
||||||
handle.operations.clear()
|
handle.operations.clear()
|
||||||
|
|
||||||
controller.togglePlayPause()
|
controller.togglePlayPause()
|
||||||
await { handle.operations.contains("play") }
|
await { handle.operations.contains("play") }
|
||||||
|
|
||||||
assertEquals(listOf("prepare", "play"), handle.operations)
|
assertEquals(listOf("play"), handle.operations)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user