playback: keep speculative prepare failures quiet

A restore now prepares the saved window before any play gesture, so a
network failure at launch reached the error listener and showed a toast
even though the user had not asked to play. Only report playback errors
when playback was requested.

The new tests now wait for the prepare operation rather than the window
contents, which can be observed a poll before the prepare lands.
This commit is contained in:
austinried
2026-11-04 11:12:07 +00:00
parent 484cc55385
commit 09baaeb77d
2 changed files with 22 additions and 5 deletions
@@ -1452,7 +1452,7 @@ class PlaybackController(
}
override fun onError(message: UiMessage) {
showMessage(message)
if (player?.playWhenReady == true) showMessage(message)
refresh()
}
}
@@ -348,15 +348,33 @@ class PlaybackControllerTest {
runBlocking { queues.replace(listOf(queues.albumEntry(1, "al1"))) }
controller.connect()
await { handle.items.isNotEmpty() }
await { handle.operations.contains("prepare") }
assertTrue(handle.operations.contains("prepare"))
assertFalse(handle.operations.contains("play"))
assertFalse(handle.isIdle)
assertFalse(handle.playWhenReady)
assertFalse(controller.state.value.isPlaying)
}
@Test
fun aPrepareFailureBeforePlaybackIsNotReported() {
seedAlbum(3, sourceId = 1)
runBlocking { queues.replace(listOf(queues.albumEntry(1, "al1"))) }
controller.connect()
await { handle.operations.contains("prepare") }
handle.fail(UiMessage(R.string.playback_error_network))
assertTrue(messages.isEmpty())
controller.togglePlayPause()
await { handle.operations.contains("play") }
handle.fail(UiMessage(R.string.playback_error_network))
await { messages.isNotEmpty() }
assertEquals(1, messages.size)
}
@Test
fun restoringAnEmptyQueueDoesNotPrepare() {
seedAlbum(3, sourceId = 1)
@@ -387,14 +405,13 @@ class PlaybackControllerTest {
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("play"), handle.operations)
assertTrue(handle.playWhenReady)
}
@Test