From 282a944eb4efd84ddea7a8657375002dfd60c34a Mon Sep 17 00:00:00 2001 From: ibaker Date: Fri, 17 May 2024 01:31:13 -0700 Subject: [PATCH] Throw errors from `WebvttPlaybackTest.stallUntilPlayerCondition` Before this change, if a playback error is thrown the test fails with a timeout and no additional info: ``` java.util.concurrent.TimeoutException at androidx.media3.exoplayer.e2etest.WebvttPlaybackTest.stallPlayerUntilCondition(WebvttPlaybackTest.java:361) ``` After this change, the test failure includes a much more useful stack trace, e.g. from https://github.com/androidx/media/commit/0352db9a375cff16b14e3e8a653e30dcfa589b74: ``` Caused by: java.lang.IllegalStateException: Legacy decoding is disabled, can't handle text/vtt samples (expected application/x-media3-cues). at androidx.media3.common.util.Assertions.checkState(Assertions.java:100) at androidx.media3.exoplayer.text.TextRenderer.assertLegacyDecodingEnabledIfRequired(TextRenderer.java:587) at androidx.media3.exoplayer.text.TextRenderer.onStreamChanged(TextRenderer.java:210) ``` PiperOrigin-RevId: 634672138 --- .../media3/exoplayer/e2etest/WebvttPlaybackTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/WebvttPlaybackTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/WebvttPlaybackTest.java index fa170d4c78..3579519754 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/WebvttPlaybackTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/e2etest/WebvttPlaybackTest.java @@ -354,7 +354,9 @@ public class WebvttPlaybackTest { private static void stallPlayerUntilCondition(ExoPlayer player, AtomicBoolean condition) throws Exception { long timeoutTimeMs = Clock.DEFAULT.currentTimeMillis() + RobolectricUtil.DEFAULT_TIMEOUT_MS; - while (!condition.get()) { + while (!condition.get() + && (player.getPlaybackState() == Player.STATE_READY + || player.getPlaybackState() == Player.STATE_BUFFERING)) { // Trigger more work at the current time until the condition is fulfilled. if (Clock.DEFAULT.currentTimeMillis() >= timeoutTimeMs) { throw new TimeoutException(); @@ -363,5 +365,8 @@ public class WebvttPlaybackTest { player.play(); run(player).untilPendingCommandsAreFullyHandled(); } + if (player.getPlayerError() != null) { + throw player.getPlayerError(); + } } }