playback: resolve the pending tap preference inside the start lock

This commit is contained in:
austinried
2026-11-12 07:53:06 +00:00
parent 2bbff7e477
commit d05fb6fc07
2 changed files with 35 additions and 10 deletions
@@ -992,29 +992,26 @@ class PlaybackController(
}
scope.launch {
startLock.withLock {
startLocked(entry, startPosition, behavior ?: preferences.songTapBehavior().first())
startLocked(entry, startPosition, behavior)
}
}
}
private suspend fun startPending(pending: PendingPlay) {
start(pending.entry, pending.position, pending.behavior ?: preferences.songTapBehavior().first())
startLock.withLock {
startLocked(pending.entry, pending.position, pending.behavior)
}
}
private suspend fun start(
entry: QueueEntry,
startPosition: Long,
behavior: SongTapBehavior,
) = startLock.withLock { startLocked(entry, startPosition, behavior) }
private suspend fun startLocked(
entry: QueueEntry,
startPosition: Long,
behavior: SongTapBehavior,
behavior: SongTapBehavior?,
) {
val resolved = behavior ?: preferences.songTapBehavior().first()
val modes = queueRepository.modes()
val shuffle =
when (behavior) {
when (resolved) {
SongTapBehavior.InOrder -> false
SongTapBehavior.KeepShuffle -> modes.shuffle
SongTapBehavior.Shuffle -> true
@@ -2613,6 +2613,34 @@ class PlaybackControllerTest {
assertEquals(1L, slowController.state.value.position)
}
@Test
fun aSongTappedWhileThePlayerConnectsKeepsItsOrder() {
seedAlbum(3, sourceId = 1)
val (slowPrefs, entered, gate) = gatedSongTapPreferences()
val slowController =
PlaybackController(
sources,
queues,
FakePlayerConnection(handle),
downloads,
slowPrefs,
scope = CoroutineScope(SupervisorJob() + dispatcher).also { extraScopes += it },
)
slowController.playAlbum(1, "al1", 0)
runBlocking { entered.await() }
slowController.playAlbum(1, "al1", 1)
gate.complete(Unit)
runBlocking { delay(1_000) }
assertEquals(
"s2",
slowController.state.value.item
?.id,
)
assertEquals(1L, slowController.state.value.position)
}
@Test
fun jumpingInTheQueueWhileShuffledKeepsTheOrder() {
seedAlbum(5, sourceId = 1)