mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-12 15:46:34 +01:00
playback: resolve the pending tap preference inside the start lock
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user