diff --git a/library/common/src/main/java/com/google/android/exoplayer2/Player.java b/library/common/src/main/java/com/google/android/exoplayer2/Player.java index bbd8d9237c..1a51a89baf 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/Player.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/Player.java @@ -140,7 +140,7 @@ public interface Player { * *

The provided {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata} * and the static and dynamic metadata from the {@link TrackSelection#getFormat(int) track - * selections' formats} and {@link MetadataOutput#onMetadata(Metadata)}. + * selections' formats} and {@link Listener#onMetadata(Metadata)}. * *

{@link #onEvents(Player, Events)} will also be called to report this event along with * other events that happen in the same {@link Looper} message queue iteration. @@ -1924,7 +1924,7 @@ public interface Player { * *

This {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata} and the * static and dynamic metadata from the {@link TrackSelection#getFormat(int) track selections' - * formats} and {@link MetadataOutput#onMetadata(Metadata)}. + * formats} and {@link Listener#onMetadata(Metadata)}. */ MediaMetadata getMediaMetadata(); diff --git a/library/core/src/androidTest/java/com/google/android/exoplayer2/ClippedPlaybackTest.java b/library/core/src/androidTest/java/com/google/android/exoplayer2/ClippedPlaybackTest.java index e5a2fac4d9..81d39c65c2 100644 --- a/library/core/src/androidTest/java/com/google/android/exoplayer2/ClippedPlaybackTest.java +++ b/library/core/src/androidTest/java/com/google/android/exoplayer2/ClippedPlaybackTest.java @@ -22,7 +22,6 @@ import android.net.Uri; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.source.ClippingMediaSource; import com.google.android.exoplayer2.text.Cue; -import com.google.android.exoplayer2.text.TextOutput; import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.MimeTypes; import com.google.common.collect.ImmutableList; @@ -56,34 +55,22 @@ public final class ClippedPlaybackTest { .setClipEndPositionMs(1000) .build(); AtomicReference player = new AtomicReference<>(); - CapturingTextOutput textOutput = new CapturingTextOutput(); - ConditionVariable playbackEnded = new ConditionVariable(); + TextCapturingPlaybackListener textCapturer = new TextCapturingPlaybackListener(); getInstrumentation() .runOnMainSync( () -> { player.set(new SimpleExoPlayer.Builder(getInstrumentation().getContext()).build()); - player.get().addTextOutput(textOutput); - player - .get() - .addListener( - new Player.Listener() { - @Override - public void onPlaybackStateChanged(@Player.State int playbackState) { - if (playbackState == Player.STATE_ENDED) { - playbackEnded.open(); - } - } - }); + player.get().addListener(textCapturer); player.get().setMediaItem(mediaItem); player.get().prepare(); player.get().play(); }); - playbackEnded.block(); + textCapturer.block(); getInstrumentation().runOnMainSync(() -> player.get().release()); getInstrumentation().waitForIdleSync(); - assertThat(Iterables.getOnlyElement(Iterables.concat(textOutput.cues)).text.toString()) + assertThat(Iterables.getOnlyElement(Iterables.concat(textCapturer.cues)).text.toString()) .isEqualTo("This is the first subtitle."); } @@ -110,42 +97,32 @@ public final class ClippedPlaybackTest { .setClipEndPositionMs(4_000) .build()); AtomicReference player = new AtomicReference<>(); - CapturingTextOutput textOutput = new CapturingTextOutput(); - ConditionVariable playbackEnded = new ConditionVariable(); + TextCapturingPlaybackListener textCapturer = new TextCapturingPlaybackListener(); getInstrumentation() .runOnMainSync( () -> { player.set(new SimpleExoPlayer.Builder(getInstrumentation().getContext()).build()); - player.get().addTextOutput(textOutput); - player - .get() - .addListener( - new Player.Listener() { - @Override - public void onPlaybackStateChanged(@Player.State int playbackState) { - if (playbackState == Player.STATE_ENDED) { - playbackEnded.open(); - } - } - }); + player.get().addListener(textCapturer); player.get().setMediaItems(mediaItems); player.get().prepare(); player.get().play(); }); - playbackEnded.block(); + textCapturer.block(); getInstrumentation().runOnMainSync(() -> player.get().release()); getInstrumentation().waitForIdleSync(); - assertThat(Iterables.getOnlyElement(Iterables.concat(textOutput.cues)).text.toString()) + assertThat(Iterables.getOnlyElement(Iterables.concat(textCapturer.cues)).text.toString()) .isEqualTo("This is the first subtitle."); } - private static class CapturingTextOutput implements TextOutput { + private static class TextCapturingPlaybackListener implements Player.Listener { + private final ConditionVariable playbackEnded; private final List> cues; - private CapturingTextOutput() { + private TextCapturingPlaybackListener() { + playbackEnded = new ConditionVariable(); cues = new ArrayList<>(); } @@ -153,5 +130,16 @@ public final class ClippedPlaybackTest { public void onCues(List cues) { this.cues.add(cues); } + + @Override + public void onPlaybackStateChanged(@Player.State int playbackState) { + if (playbackState == Player.STATE_ENDED) { + playbackEnded.open(); + } + } + + public void block() throws InterruptedException { + playbackEnded.block(); + } } } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java index 530b81e138..4ef12414d0 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java @@ -1490,7 +1490,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider { @Override public void onCues(List cues) { if (subtitleView != null) { - subtitleView.onCues(cues); + subtitleView.setCues(cues); } } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java index b5a2822c8d..2fb299048b 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java @@ -1531,7 +1531,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { @Override public void onCues(List cues) { if (subtitleView != null) { - subtitleView.onCues(cues); + subtitleView.setCues(cues); } } diff --git a/robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/PlaybackOutput.java b/robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/PlaybackOutput.java index 2724835e4e..0fe00c4110 100644 --- a/robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/PlaybackOutput.java +++ b/robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/PlaybackOutput.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.robolectric; import android.graphics.Bitmap; import androidx.annotation.Nullable; +import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.dvbsi.AppInfoTable; @@ -63,8 +64,18 @@ public final class PlaybackOutput implements Dumper.Dumpable { // TODO: Consider passing playback position into MetadataOutput and TextOutput. Calling // player.getCurrentPosition() inside onMetadata/Cues will likely be non-deterministic // because renderer-thread != playback-thread. - player.addMetadataOutput(metadatas::add); - // TODO(internal b/174661563): Output subtitle data when it's not flaky. + player.addListener( + new Player.Listener() { + @Override + public void onMetadata(Metadata metadata) { + metadatas.add(metadata); + } + + @Override + public void onCues(List cues) { + // TODO(internal b/174661563): Output subtitle data when it's not flaky. + } + }); } /** diff --git a/robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/TestPlayerRunHelper.java b/robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/TestPlayerRunHelper.java index a58af6b55b..c31a310de0 100644 --- a/robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/TestPlayerRunHelper.java +++ b/robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/TestPlayerRunHelper.java @@ -27,7 +27,6 @@ import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.Util; -import com.google.android.exoplayer2.video.VideoListener; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -252,7 +251,7 @@ public class TestPlayerRunHelper { } /** - * Runs tasks of the main {@link Looper} until the {@link VideoListener#onRenderedFirstFrame} + * Runs tasks of the main {@link Looper} until the {@link Player.Listener#onRenderedFirstFrame} * callback is called or a playback error occurs. * *

If a playback error occurs it will be thrown wrapped in an {@link IllegalStateException}..