diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/CompositionPlayerSeekTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/CompositionPlayerSeekTest.java index 95714dfc97..922cba70a8 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/CompositionPlayerSeekTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/CompositionPlayerSeekTest.java @@ -23,6 +23,7 @@ import static androidx.media3.transformer.AndroidTestUtil.PNG_ASSET; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import static com.google.common.collect.Iterables.getLast; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static java.util.concurrent.TimeUnit.MILLISECONDS; import android.content.Context; @@ -33,9 +34,12 @@ import androidx.media3.common.Effect; import androidx.media3.common.GlObjectsProvider; import androidx.media3.common.GlTextureInfo; import androidx.media3.common.MediaItem; +import androidx.media3.common.PlaybackException; +import androidx.media3.common.Player; import androidx.media3.common.PreviewingVideoGraph; import androidx.media3.common.VideoFrameProcessingException; import androidx.media3.common.VideoGraph; +import androidx.media3.common.util.NullableType; import androidx.media3.common.util.Util; import androidx.media3.effect.GlEffect; import androidx.media3.effect.PreviewingSingleInputVideoGraph; @@ -47,8 +51,8 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; -import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -587,6 +591,7 @@ public class CompositionPlayerSeekTest { List editedMediaItems = createEditedMediaItems(mediaItems, durationsUs, videoEffect); CountDownLatch videoGraphEnded = new CountDownLatch(1); + AtomicReference<@NullableType PlaybackException> playbackException = new AtomicReference<>(); getInstrumentation() .runOnMainSync( @@ -600,6 +605,14 @@ public class CompositionPlayerSeekTest { // surface otherwise the player will skip/drop video frames. compositionPlayer.setVideoSurfaceView(surfaceView); compositionPlayer.addListener(playerTestListener); + compositionPlayer.addListener( + new Player.Listener() { + @Override + public void onPlayerError(PlaybackException error) { + playbackException.set(error); + frameCountBeforeBlockLatch.unblock(); + } + }); compositionPlayer.setComposition( new Composition.Builder( new EditedMediaItemSequence.Builder(editedMediaItems).build()) @@ -609,7 +622,12 @@ public class CompositionPlayerSeekTest { }); // Wait until the number of frames are received, block further input on the shader program. - frameCountBeforeBlockLatch.await(); + assertWithMessage("Timeout reached while waiting for frames.") + .that(frameCountBeforeBlockLatch.await()) + .isTrue(); + if (playbackException.get() != null) { + throw playbackException.get(); + } getInstrumentation().runOnMainSync(() -> compositionPlayer.seekTo(seekTimeMs)); playerTestListener.waitUntilPlayerEnded(); @@ -757,10 +775,8 @@ public class CompositionPlayerSeekTest { latch = new CountDownLatch(count); } - public void await() throws InterruptedException, TimeoutException { - if (!latch.await(TEST_TIMEOUT_MS, MILLISECONDS)) { - throw new TimeoutException(); - } + public boolean await() throws InterruptedException { + return latch.await(TEST_TIMEOUT_MS, MILLISECONDS); } public void countDown() { @@ -771,6 +787,12 @@ public class CompositionPlayerSeekTest { return latch.getCount(); } + public void unblock() { + while (latch.getCount() > 0) { + latch.countDown(); + } + } + public void reset(int count) { latch = new CountDownLatch(count); }