From d47d1ebf19a15f59629b220ef9c82b24209e89a7 Mon Sep 17 00:00:00 2001 From: samrobinson Date: Tue, 20 Jul 2021 15:24:04 +0100 Subject: [PATCH] Deprecate static metadata getter and listener method. PiperOrigin-RevId: 385781004 --- RELEASENOTES.md | 7 ++ .../exoplayer2/ext/cast/CastPlayer.java | 1 + .../android/exoplayer2/ForwardingPlayer.java | 2 + .../com/google/android/exoplayer2/Player.java | 52 +++++-------- .../android/exoplayer2/ExoPlayerImpl.java | 3 +- .../android/exoplayer2/SimpleExoPlayer.java | 1 + .../analytics/AnalyticsCollector.java | 1 + .../analytics/AnalyticsListener.java | 26 +++---- .../android/exoplayer2/util/EventLogger.java | 15 ---- .../android/exoplayer2/ExoPlayerTest.java | 76 ++----------------- .../exoplayer2/testutil/StubExoPlayer.java | 1 + 11 files changed, 48 insertions(+), 137 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 03939d8e65..d64c56e5b2 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -41,6 +41,13 @@ * Add a `DefaultMediaDescriptionAdapter` for the `PlayerNotificationManager`, that makes use of the `Player` `MediaMetadata` to populate the notification fields. + * Deprecate `Player.getCurrentStaticMetadata`, + `Player.Listener.onStaticMetadataChanged` and + `Player.EVENT_STATIC_METADATA_CHANGED`. Use `Player.getMediaMetadata`, + `Player.Listener.onMediaMetadataChanged` and + `Player.EVENT_MEDIA_METADATA_CHANGED` for convenient access to + structured metadata, or access the raw static metadata directly from + the `TrackSelection#getFormat()`. * Remove deprecated symbols: * Remove `Player.getPlaybackError`. Use `Player.getPlayerError` instead. * Remove `Player.getCurrentTag`. Use `Player.getCurrentMediaItem` and diff --git a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java index f5ac8bfd43..e1e752ea76 100644 --- a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java +++ b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastPlayer.java @@ -541,6 +541,7 @@ public final class CastPlayer extends BasePlayer { return currentTrackGroups; } + @Deprecated @Override public ImmutableList getCurrentStaticMetadata() { // CastPlayer does not currently support metadata. diff --git a/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java b/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java index a2ff3c3aa4..0752f28fbb 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/ForwardingPlayer.java @@ -367,6 +367,7 @@ public class ForwardingPlayer implements Player { return player.getCurrentTrackSelections(); } + @Deprecated @Override public List getCurrentStaticMetadata() { return player.getCurrentStaticMetadata(); @@ -642,6 +643,7 @@ public class ForwardingPlayer implements Player { eventListener.onTracksChanged(trackGroups, trackSelections); } + @Deprecated @Override public void onStaticMetadataChanged(List metadataList) { eventListener.onStaticMetadataChanged(metadataList); 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 795a589afb..2c89ed9264 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 @@ -32,6 +32,7 @@ import com.google.android.exoplayer2.metadata.MetadataOutput; import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.TextOutput; +import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.util.FlagSet; import com.google.android.exoplayer2.util.Util; @@ -128,30 +129,20 @@ public interface Player { TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {} /** - * Called when the static metadata changes. - * - *

The provided {@code metadataList} is an immutable list of {@link Metadata} instances, - * where the elements correspond to the {@link #getCurrentTrackSelections() current track - * selections}, or an empty list if there are no track selections or the selected tracks contain - * no static metadata. - * - *

The metadata is considered static in the sense that it comes from the tracks' declared - * Formats, rather than being timed (or dynamic) metadata, which is represented within a - * metadata track. - * - *

{@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. - * - * @param metadataList The static metadata. + * @deprecated Use {@link Player#getMediaMetadata()} and {@link + * #onMediaMetadataChanged(MediaMetadata)} for access to structured metadata, or access the + * raw static metadata directly from the {@link TrackSelection#getFormat(int) track + * selections' formats}. */ + @Deprecated default void onStaticMetadataChanged(List metadataList) {} /** * Called when the combined {@link MediaMetadata} changes. * *

The provided {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata} - * and the static and dynamic metadata sourced from {@link #onStaticMetadataChanged(List)} and - * {@link MetadataOutput#onMetadata(Metadata)}. + * and the static and dynamic metadata from the {@link TrackSelection#getFormat(int) track + * selections' formats} and {@link MetadataOutput#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. @@ -987,9 +978,6 @@ public interface Player { @Override default void onPlaylistMetadataChanged(MediaMetadata mediaMetadata) {} - - @Override - default void onStaticMetadataChanged(List metadataList) {} } /** @@ -1215,8 +1203,8 @@ public interface Player { int EVENT_MEDIA_ITEM_TRANSITION = 1; /** {@link #getCurrentTrackGroups()} or {@link #getCurrentTrackSelections()} changed. */ int EVENT_TRACKS_CHANGED = 2; - /** {@link #getCurrentStaticMetadata()} changed. */ - int EVENT_STATIC_METADATA_CHANGED = 3; + /** @deprecated Use {@link #EVENT_MEDIA_METADATA_CHANGED} for structured metadata changes. */ + @Deprecated int EVENT_STATIC_METADATA_CHANGED = 3; /** {@link #isLoading()} ()} changed. */ int EVENT_IS_LOADING_CHANGED = 4; /** {@link #getPlaybackState()} changed. */ @@ -1926,18 +1914,12 @@ public interface Player { TrackSelectionArray getCurrentTrackSelections(); /** - * Returns the current static metadata for the track selections. - * - *

The returned {@code metadataList} is an immutable list of {@link Metadata} instances, where - * the elements correspond to the {@link #getCurrentTrackSelections() current track selections}, - * or an empty list if there are no track selections or the selected tracks contain no static - * metadata. - * - *

This metadata is considered static in that it comes from the tracks' declared Formats, - * rather than being timed (or dynamic) metadata, which is represented within a metadata track. - * - * @see Listener#onStaticMetadataChanged(List) + * @deprecated Use {@link #getMediaMetadata()} and {@link + * Listener#onMediaMetadataChanged(MediaMetadata)} for access to structured metadata, or + * access the raw static metadata directly from the {@link TrackSelection#getFormat(int) track + * selections' formats}. */ + @Deprecated List getCurrentStaticMetadata(); /** @@ -1945,8 +1927,8 @@ public interface Player { * supported. * *

This {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata} and the - * static and dynamic metadata sourced from {@link Listener#onStaticMetadataChanged(List)} and - * {@link MetadataOutput#onMetadata(Metadata)}. + * static and dynamic metadata from the {@link TrackSelection#getFormat(int) track selections' + * formats} and {@link MetadataOutput#onMetadata(Metadata)}. */ MediaMetadata getMediaMetadata(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index 6a528c21a4..85723c4dee 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -1004,6 +1004,7 @@ import java.util.concurrent.CopyOnWriteArraySet; return new TrackSelectionArray(playbackInfo.trackSelectorResult.selections); } + @Deprecated @Override public List getCurrentStaticMetadata() { return playbackInfo.staticMetadata; @@ -1264,7 +1265,7 @@ import java.util.concurrent.CopyOnWriteArraySet; .windowIndex; mediaItem = newPlaybackInfo.timeline.getWindow(windowIndex, window).mediaItem; } - mediaMetadata = mediaItem != null ? mediaItem.mediaMetadata : MediaMetadata.EMPTY; + newMediaMetadata = mediaItem != null ? mediaItem.mediaMetadata : MediaMetadata.EMPTY; } if (!previousPlaybackInfo.staticMetadata.equals(newPlaybackInfo.staticMetadata)) { newMediaMetadata = diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java index 1625ae0bb7..148e4c8845 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java @@ -1723,6 +1723,7 @@ public class SimpleExoPlayer extends BasePlayer return player.getCurrentTrackSelections(); } + @Deprecated @Override public List getCurrentStaticMetadata() { verifyApplicationThread(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/analytics/AnalyticsCollector.java b/library/core/src/main/java/com/google/android/exoplayer2/analytics/AnalyticsCollector.java index 669345a1f3..4e10cce9c7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/analytics/AnalyticsCollector.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/analytics/AnalyticsCollector.java @@ -595,6 +595,7 @@ public class AnalyticsCollector listener -> listener.onTracksChanged(eventTime, trackGroups, trackSelections)); } + @Deprecated @Override public final void onStaticMetadataChanged(List metadataList) { EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/analytics/AnalyticsListener.java b/library/core/src/main/java/com/google/android/exoplayer2/analytics/AnalyticsListener.java index 1588c48588..19c1361c0a 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/analytics/AnalyticsListener.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/analytics/AnalyticsListener.java @@ -48,6 +48,7 @@ import com.google.android.exoplayer2.source.LoadEventInfo; import com.google.android.exoplayer2.source.MediaLoadData; import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId; import com.google.android.exoplayer2.source.TrackGroupArray; +import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.util.FlagSet; import com.google.android.exoplayer2.video.VideoDecoderOutputBufferRenderer; @@ -225,8 +226,8 @@ public interface AnalyticsListener { * {@link Player#getCurrentTrackGroups()} or {@link Player#getCurrentTrackSelections()} changed. */ int EVENT_TRACKS_CHANGED = Player.EVENT_TRACKS_CHANGED; - /** {@link Player#getCurrentStaticMetadata()} changed. */ - int EVENT_STATIC_METADATA_CHANGED = Player.EVENT_STATIC_METADATA_CHANGED; + /** @deprecated See {@link Player#EVENT_MEDIA_METADATA_CHANGED}. */ + @Deprecated int EVENT_STATIC_METADATA_CHANGED = Player.EVENT_STATIC_METADATA_CHANGED; /** {@link Player#isLoading()} ()} changed. */ int EVENT_IS_LOADING_CHANGED = Player.EVENT_IS_LOADING_CHANGED; /** {@link Player#getPlaybackState()} changed. */ @@ -682,28 +683,19 @@ public interface AnalyticsListener { EventTime eventTime, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {} /** - * Called when the static metadata changes. - * - *

The provided {@code metadataList} is an immutable list of {@link Metadata} instances, where - * the elements correspond to the current track selections (as returned by {@link - * #onTracksChanged(EventTime, TrackGroupArray, TrackSelectionArray)}, or an empty list if there - * are no track selections or the selected tracks contain no static metadata. - * - *

The metadata is considered static in the sense that it comes from the tracks' declared - * Formats, rather than being timed (or dynamic) metadata, which is represented within a metadata - * track. - * - * @param eventTime The event time. - * @param metadataList The static metadata. + * @deprecated Use {@link Player#getMediaMetadata()} and {@link #onMediaMetadataChanged(EventTime, + * MediaMetadata)} for access to structured metadata, or access the raw static metadata + * directly from the {@link TrackSelection#getFormat(int) track selections' formats}. */ + @Deprecated default void onStaticMetadataChanged(EventTime eventTime, List metadataList) {} /** * Called when the combined {@link MediaMetadata} changes. * *

The provided {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata} - * and the static and dynamic metadata sourced from {@link - * Player.Listener#onStaticMetadataChanged(List)} and {@link MetadataOutput#onMetadata(Metadata)}. + * and the static and dynamic metadata from the {@link TrackSelection#getFormat(int) track + * selections' formats} and {@link MetadataOutput#onMetadata(Metadata)}. * * @param eventTime The event time. * @param mediaMetadata The combined {@link MediaMetadata}. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java b/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java index cf3dc322b7..391c58f513 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/EventLogger.java @@ -47,7 +47,6 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.video.VideoSize; import java.io.IOException; import java.text.NumberFormat; -import java.util.List; import java.util.Locale; /** Logs events from {@link Player} and other core components using {@link Log}. */ @@ -334,20 +333,6 @@ public class EventLogger implements AnalyticsListener { logd("]"); } - @Override - public void onStaticMetadataChanged(EventTime eventTime, List metadataList) { - logd("staticMetadata [" + getEventTimeString(eventTime)); - for (int i = 0; i < metadataList.size(); i++) { - Metadata metadata = metadataList.get(i); - if (metadata.length() != 0) { - logd(" Metadata:" + i + " ["); - printMetadata(metadata, " "); - logd(" ]"); - } - } - logd("]"); - } - @Override public void onMetadata(EventTime eventTime, Metadata metadata) { logd("metadata [" + getEventTimeString(eventTime)); diff --git a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java index 2d32923a5a..b0ef758b0f 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java @@ -8937,72 +8937,6 @@ public final class ExoPlayerTest { runUntilPlaybackState(player, Player.STATE_ENDED); } - @Test - public void staticMetadata_callbackIsCalledCorrectlyAndMatchesGetter() throws Exception { - Format videoFormat = - new Format.Builder() - .setSampleMimeType(MimeTypes.VIDEO_H264) - .setMetadata( - new Metadata( - new TextInformationFrame( - /* id= */ "TT2", - /* description= */ "Video", - /* value= */ "Video track name"))) - .build(); - Format audioFormat = - new Format.Builder() - .setSampleMimeType(MimeTypes.AUDIO_AAC) - .setMetadata( - new Metadata( - new TextInformationFrame( - /* id= */ "TT2", - /* description= */ "Audio", - /* value= */ "Audio track name"))) - .build(); - Player.Listener playerListener = mock(Player.Listener.class); - Timeline fakeTimeline = - new FakeTimeline( - new TimelineWindowDefinition( - /* isSeekable= */ true, /* isDynamic= */ false, /* durationUs= */ 100000)); - SimpleExoPlayer player = new TestExoPlayerBuilder(context).build(); - - player.setMediaSource(new FakeMediaSource(fakeTimeline, videoFormat, audioFormat)); - player.addListener(playerListener); - player.prepare(); - player.play(); - runUntilPlaybackState(player, Player.STATE_ENDED); - List metadata = player.getCurrentStaticMetadata(); - player.release(); - - assertThat(metadata).containsExactly(videoFormat.metadata, audioFormat.metadata).inOrder(); - verify(playerListener) - .onStaticMetadataChanged(ImmutableList.of(videoFormat.metadata, audioFormat.metadata)); - } - - @Test - public void staticMetadata_callbackIsNotCalledWhenMetadataEmptyAndGetterReturnsEmptyList() - throws Exception { - Format videoFormat = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_H264).build(); - Format audioFormat = new Format.Builder().setSampleMimeType(MimeTypes.AUDIO_AAC).build(); - Player.Listener playerListener = mock(Player.Listener.class); - Timeline fakeTimeline = - new FakeTimeline( - new TimelineWindowDefinition( - /* isSeekable= */ true, /* isDynamic= */ false, /* durationUs= */ 100000)); - SimpleExoPlayer player = new TestExoPlayerBuilder(context).build(); - - player.setMediaSource(new FakeMediaSource(fakeTimeline, videoFormat, audioFormat)); - player.addListener(playerListener); - player.prepare(); - player.play(); - runUntilPlaybackState(player, Player.STATE_ENDED); - List metadata = player.getCurrentStaticMetadata(); - player.release(); - - assertThat(metadata).isEmpty(); - verify(playerListener, never()).onStaticMetadataChanged(any()); - } - @Test public void targetLiveOffsetInMedia_adjustsLiveOffsetToTargetOffset() throws Exception { long windowStartUnixTimeMs = 987_654_321_000L; @@ -9495,7 +9429,11 @@ public final class ExoPlayerTest { Format formatWithStaticMetadata = new Format.Builder() .setSampleMimeType(MimeTypes.VIDEO_H264) - .setMetadata(new Metadata(new BinaryFrame(/* id= */ "", /* data= */ new byte[0]))) + .setMetadata( + new Metadata( + new BinaryFrame(/* id= */ "", /* data= */ new byte[0]), + new TextInformationFrame( + /* id= */ "TT2", /* description= */ null, /* value= */ "title"))) .build(); // Set multiple values together. @@ -9554,7 +9492,7 @@ public final class ExoPlayerTest { verify(listener, atLeastOnce()).onPlaybackStateChanged(anyInt()); verify(listener, atLeastOnce()).onIsLoadingChanged(anyBoolean()); verify(listener, atLeastOnce()).onTracksChanged(any(), any()); - verify(listener, atLeastOnce()).onStaticMetadataChanged(any()); + verify(listener, atLeastOnce()).onMediaMetadataChanged(any()); verify(listener, atLeastOnce()).onPlayWhenReadyChanged(anyBoolean(), anyInt()); verify(listener, atLeastOnce()).onIsPlayingChanged(anyBoolean()); verify(listener, atLeastOnce()).onPlayerErrorChanged(any()); @@ -9572,7 +9510,7 @@ public final class ExoPlayerTest { assertThat(containsEvent(allEvents, Player.EVENT_PLAYBACK_STATE_CHANGED)).isTrue(); assertThat(containsEvent(allEvents, Player.EVENT_IS_LOADING_CHANGED)).isTrue(); assertThat(containsEvent(allEvents, Player.EVENT_TRACKS_CHANGED)).isTrue(); - assertThat(containsEvent(allEvents, Player.EVENT_STATIC_METADATA_CHANGED)).isTrue(); + assertThat(containsEvent(allEvents, Player.EVENT_MEDIA_METADATA_CHANGED)).isTrue(); assertThat(containsEvent(allEvents, Player.EVENT_PLAY_WHEN_READY_CHANGED)).isTrue(); assertThat(containsEvent(allEvents, Player.EVENT_IS_PLAYING_CHANGED)).isTrue(); assertThat(containsEvent(allEvents, Player.EVENT_PLAYER_ERROR)).isTrue(); diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java index 42b1fccac5..836a4bba05 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java @@ -375,6 +375,7 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer { throw new UnsupportedOperationException(); } + @Deprecated @Override public List getCurrentStaticMetadata() { throw new UnsupportedOperationException();