From 25e58f5f2a6c15138daef4103ab2aff711e662ff Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 21 Feb 2022 15:08:12 +0000 Subject: [PATCH] Remove deprecated Player track methods getCurrentTrackGroups and getCurrentTrackSelections are retained for now, but moved from Player to ExoPlayer, to ease the transition for some application code that currently uses these methods. PiperOrigin-RevId: 430036355 --- RELEASENOTES.md | 7 ++ .../exoplayer2/ext/cast/CastPlayer.java | 80 +++------------ .../ext/cast/CastTrackSelection.java | 98 ------------------- .../ext/cast/CastTrackSelectionTest.java | 77 --------------- .../android/exoplayer2/ForwardingPlayer.java | 24 ----- .../com/google/android/exoplayer2/Player.java | 45 +-------- .../google/android/exoplayer2/ExoPlayer.java | 21 ++++ .../android/exoplayer2/ExoPlayerImpl.java | 5 - .../analytics/DefaultAnalyticsCollector.java | 9 -- .../android/exoplayer2/ExoPlayerTest.java | 59 +++++------ .../exoplayer2/testutil/StubExoPlayer.java | 12 +++ .../exoplayer2/testutil/StubPlayer.java | 12 --- 12 files changed, 85 insertions(+), 364 deletions(-) delete mode 100644 extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastTrackSelection.java delete mode 100644 extensions/cast/src/test/java/com/google/android/exoplayer2/ext/cast/CastTrackSelectionTest.java diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 3f5a7e28ec..3246705f47 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -200,6 +200,13 @@ `DefaultRenderersFactory#setAllowedVideoJoiningTimeMs` instead. * Remove all public `CronetDataSource` constructors. Use `CronetDataSource.Factory` instead. + * Remove `Player.Listener.onTracksChanged`. Use + `Player.Listener.onTracksInfoChanged` instead. + * Remove `Player.getCurrentTrackGroups` and + `Player.getCurrentTrackSelections`. Use `Player.getCurrentTracksInfo` + instead. You can also continue to use `ExoPlayer.getCurrentTrackGroups` + and `ExoPlayer.getCurrentTrackSelections`, although these methods remain + deprecated. * Change the following `IntDefs` to `@Target(TYPE_USE)` only. This may break the compilation of usages in Kotlin, which can be fixed by moving the annotation to annotate the type (`Int`). 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 b7aad3e735..819a590052 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 @@ -38,18 +38,15 @@ import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.TracksInfo; +import com.google.android.exoplayer2.TracksInfo.TrackGroupInfo; import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.source.TrackGroup; -import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.text.Cue; -import com.google.android.exoplayer2.trackselection.TrackSelection; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.ListenerSet; import com.google.android.exoplayer2.util.Log; -import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.video.VideoSize; import com.google.android.gms.cast.CastStatusCodes; @@ -67,7 +64,6 @@ import com.google.android.gms.common.api.PendingResult; import com.google.android.gms.common.api.ResultCallback; import com.google.common.collect.ImmutableList; import java.util.List; -import org.checkerframework.checker.nullness.compatqual.NullableType; import org.checkerframework.checker.nullness.qual.RequiresNonNull; /** @@ -113,13 +109,10 @@ public final class CastPlayer extends BasePlayer { private static final String TAG = "CastPlayer"; - private static final int RENDERER_COUNT = 3; private static final int RENDERER_INDEX_VIDEO = 0; private static final int RENDERER_INDEX_AUDIO = 1; private static final int RENDERER_INDEX_TEXT = 2; private static final long PROGRESS_REPORT_PERIOD_MS = 1000; - private static final TrackSelectionArray EMPTY_TRACK_SELECTION_ARRAY = - new TrackSelectionArray(null, null, null); private static final long[] EMPTY_TRACK_ID_ARRAY = new long[0]; private final CastContext castContext; @@ -144,8 +137,6 @@ public final class CastPlayer extends BasePlayer { private final StateHolder playbackParameters; @Nullable private RemoteMediaClient remoteMediaClient; private CastTimeline currentTimeline; - private TrackGroupArray currentTrackGroups; - private TrackSelectionArray currentTrackSelection; private TracksInfo currentTracksInfo; private Commands availableCommands; private @Player.State int playbackState; @@ -222,8 +213,6 @@ public final class CastPlayer extends BasePlayer { playbackParameters = new StateHolder<>(PlaybackParameters.DEFAULT); playbackState = STATE_IDLE; currentTimeline = CastTimeline.EMPTY_CAST_TIMELINE; - currentTrackGroups = TrackGroupArray.EMPTY; - currentTrackSelection = EMPTY_TRACK_SELECTION_ARRAY; currentTracksInfo = TracksInfo.EMPTY; availableCommands = new Commands.Builder().addAll(PERMANENT_AVAILABLE_COMMANDS).build(); pendingSeekWindowIndex = C.INDEX_UNSET; @@ -555,16 +544,6 @@ public final class CastPlayer extends BasePlayer { return false; } - @Override - public TrackGroupArray getCurrentTrackGroups() { - return currentTrackGroups; - } - - @Override - public TrackSelectionArray getCurrentTrackSelections() { - return currentTrackSelection; - } - @Override public TracksInfo getCurrentTracksInfo() { return currentTracksInfo; @@ -839,9 +818,6 @@ public final class CastPlayer extends BasePlayer { getCurrentMediaItem(), MEDIA_ITEM_TRANSITION_REASON_AUTO)); } if (updateTracksAndSelectionsAndNotifyIfChanged()) { - listeners.queueEvent( - Player.EVENT_TRACKS_CHANGED, - listener -> listener.onTracksChanged(currentTrackGroups, currentTrackSelection)); listeners.queueEvent( Player.EVENT_TRACKS_CHANGED, listener -> listener.onTracksInfoChanged(currentTracksInfo)); } @@ -998,55 +974,33 @@ public final class CastPlayer extends BasePlayer { return false; } - MediaStatus mediaStatus = getMediaStatus(); - MediaInfo mediaInfo = mediaStatus != null ? mediaStatus.getMediaInfo() : null; + @Nullable MediaStatus mediaStatus = getMediaStatus(); + @Nullable MediaInfo mediaInfo = mediaStatus != null ? mediaStatus.getMediaInfo() : null; + @Nullable List castMediaTracks = mediaInfo != null ? mediaInfo.getMediaTracks() : null; if (castMediaTracks == null || castMediaTracks.isEmpty()) { - boolean hasChanged = !currentTrackGroups.isEmpty(); - currentTrackGroups = TrackGroupArray.EMPTY; - currentTrackSelection = EMPTY_TRACK_SELECTION_ARRAY; + boolean hasChanged = !TracksInfo.EMPTY.equals(currentTracksInfo); currentTracksInfo = TracksInfo.EMPTY; return hasChanged; } - long[] activeTrackIds = mediaStatus.getActiveTrackIds(); + @Nullable long[] activeTrackIds = mediaStatus.getActiveTrackIds(); if (activeTrackIds == null) { activeTrackIds = EMPTY_TRACK_ID_ARRAY; } - TrackGroup[] trackGroups = new TrackGroup[castMediaTracks.size()]; - @NullableType TrackSelection[] trackSelections = new TrackSelection[RENDERER_COUNT]; - TracksInfo.TrackGroupInfo[] trackGroupInfos = - new TracksInfo.TrackGroupInfo[castMediaTracks.size()]; + TrackGroupInfo[] trackGroupInfos = new TrackGroupInfo[castMediaTracks.size()]; for (int i = 0; i < castMediaTracks.size(); i++) { MediaTrack mediaTrack = castMediaTracks.get(i); - trackGroups[i] = + TrackGroup trackGroup = new TrackGroup(/* id= */ Integer.toString(i), CastUtils.mediaTrackToFormat(mediaTrack)); - - long id = mediaTrack.getId(); - @C.TrackType int trackType = MimeTypes.getTrackType(mediaTrack.getContentType()); - int rendererIndex = getRendererIndexForTrackType(trackType); - boolean supported = rendererIndex != C.INDEX_UNSET; - boolean selected = - isTrackActive(id, activeTrackIds) && supported && trackSelections[rendererIndex] == null; - if (selected) { - trackSelections[rendererIndex] = new CastTrackSelection(trackGroups[i]); - } - @C.FormatSupport - int[] trackSupport = new int[] {supported ? C.FORMAT_HANDLED : C.FORMAT_UNSUPPORTED_TYPE}; - final boolean[] trackSelected = new boolean[] {selected}; + @C.FormatSupport int[] trackSupport = new int[] {C.FORMAT_HANDLED}; + boolean[] trackSelected = new boolean[] {isTrackActive(mediaTrack.getId(), activeTrackIds)}; trackGroupInfos[i] = - new TracksInfo.TrackGroupInfo( - trackGroups[i], /* adaptiveSupported= */ false, trackSupport, trackSelected); + new TrackGroupInfo( + trackGroup, /* adaptiveSupported= */ false, trackSupport, trackSelected); } - TrackGroupArray newTrackGroups = new TrackGroupArray(trackGroups); - TrackSelectionArray newTrackSelections = new TrackSelectionArray(trackSelections); TracksInfo newTracksInfo = new TracksInfo(ImmutableList.copyOf(trackGroupInfos)); - - if (!newTrackGroups.equals(currentTrackGroups) - || !newTrackSelections.equals(currentTrackSelection) - || !newTracksInfo.equals(currentTracksInfo)) { - currentTrackSelection = newTrackSelections; - currentTrackGroups = newTrackGroups; + if (!newTracksInfo.equals(currentTracksInfo)) { currentTracksInfo = newTracksInfo; return true; } @@ -1305,14 +1259,6 @@ public final class CastPlayer extends BasePlayer { return false; } - private static int getRendererIndexForTrackType(@C.TrackType int trackType) { - return trackType == C.TRACK_TYPE_VIDEO - ? RENDERER_INDEX_VIDEO - : trackType == C.TRACK_TYPE_AUDIO - ? RENDERER_INDEX_AUDIO - : trackType == C.TRACK_TYPE_TEXT ? RENDERER_INDEX_TEXT : C.INDEX_UNSET; - } - private static int getCastRepeatMode(@RepeatMode int repeatMode) { switch (repeatMode) { case REPEAT_MODE_ONE: diff --git a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastTrackSelection.java b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastTrackSelection.java deleted file mode 100644 index 48f6a0e48c..0000000000 --- a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastTrackSelection.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.android.exoplayer2.ext.cast; - -import androidx.annotation.Nullable; -import com.google.android.exoplayer2.C; -import com.google.android.exoplayer2.Format; -import com.google.android.exoplayer2.source.TrackGroup; -import com.google.android.exoplayer2.trackselection.TrackSelection; -import com.google.android.exoplayer2.util.Assertions; - -/** - * {@link TrackSelection} that only selects the first track of the provided {@link TrackGroup}. - * - *

This relies on {@link CastPlayer} track groups only having one track. - */ -/* package */ class CastTrackSelection implements TrackSelection { - - private final TrackGroup trackGroup; - - /** - * @param trackGroup The {@link TrackGroup} from which the first track will only be selected. - */ - public CastTrackSelection(TrackGroup trackGroup) { - this.trackGroup = trackGroup; - } - - @Override - public int getType() { - return TYPE_UNSET; - } - - @Override - public TrackGroup getTrackGroup() { - return trackGroup; - } - - @Override - public int length() { - return 1; - } - - @Override - public Format getFormat(int index) { - Assertions.checkArgument(index == 0); - return trackGroup.getFormat(0); - } - - @Override - public int getIndexInTrackGroup(int index) { - return index == 0 ? 0 : C.INDEX_UNSET; - } - - @Override - @SuppressWarnings("ReferenceEquality") - public int indexOf(Format format) { - return format == trackGroup.getFormat(0) ? 0 : C.INDEX_UNSET; - } - - @Override - public int indexOf(int indexInTrackGroup) { - return indexInTrackGroup == 0 ? 0 : C.INDEX_UNSET; - } - - // Object overrides. - - @Override - public int hashCode() { - return System.identityHashCode(trackGroup); - } - - // Track groups are compared by identity not value, as distinct groups may have the same value. - @Override - @SuppressWarnings({"ReferenceEquality", "EqualsGetClass"}) - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - CastTrackSelection other = (CastTrackSelection) obj; - return trackGroup == other.trackGroup; - } -} diff --git a/extensions/cast/src/test/java/com/google/android/exoplayer2/ext/cast/CastTrackSelectionTest.java b/extensions/cast/src/test/java/com/google/android/exoplayer2/ext/cast/CastTrackSelectionTest.java deleted file mode 100644 index 0a30c0c4b8..0000000000 --- a/extensions/cast/src/test/java/com/google/android/exoplayer2/ext/cast/CastTrackSelectionTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.android.exoplayer2.ext.cast; - -import static com.google.common.truth.Truth.assertThat; - -import androidx.test.ext.junit.runners.AndroidJUnit4; -import com.google.android.exoplayer2.C; -import com.google.android.exoplayer2.Format; -import com.google.android.exoplayer2.source.TrackGroup; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** Test for {@link CastTrackSelection}. */ -@RunWith(AndroidJUnit4.class) -public class CastTrackSelectionTest { - - private static final TrackGroup TRACK_GROUP = - new TrackGroup(new Format.Builder().build(), new Format.Builder().build()); - - private static final CastTrackSelection SELECTION = new CastTrackSelection(TRACK_GROUP); - - @Test - public void length_isOne() { - assertThat(SELECTION.length()).isEqualTo(1); - } - - @Test - public void getTrackGroup_returnsSameGroup() { - assertThat(SELECTION.getTrackGroup()).isSameInstanceAs(TRACK_GROUP); - } - - @Test - public void getFormatSelectedTrack_isFirstTrack() { - assertThat(SELECTION.getFormat(0)).isSameInstanceAs(TRACK_GROUP.getFormat(0)); - } - - @Test - public void getIndexInTrackGroup_ofSelectedTrack_returnsFirstTrack() { - assertThat(SELECTION.getIndexInTrackGroup(0)).isEqualTo(0); - } - - @Test - public void getIndexInTrackGroup_onePastTheEnd_returnsIndexUnset() { - assertThat(SELECTION.getIndexInTrackGroup(1)).isEqualTo(C.INDEX_UNSET); - } - - @Test - public void indexOf_selectedTrack_returnsFirstTrack() { - assertThat(SELECTION.indexOf(0)).isEqualTo(0); - } - - @Test - public void indexOf_onePastTheEnd_returnsIndexUnset() { - assertThat(SELECTION.indexOf(1)).isEqualTo(C.INDEX_UNSET); - } - - @Test(expected = Exception.class) - public void getFormat_outOfBound_throws() { - CastTrackSelection selection = new CastTrackSelection(TRACK_GROUP); - - selection.getFormat(1); - } -} 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 62d4c275c6..d1e59fd39d 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 @@ -23,9 +23,7 @@ import android.view.TextureView; import androidx.annotation.Nullable; import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.metadata.Metadata; -import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.text.Cue; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.video.VideoSize; import java.util.List; @@ -446,22 +444,6 @@ public class ForwardingPlayer implements Player { player.release(); } - /** Calls {@link Player#getCurrentTrackGroups()} on the delegate and returns the result. */ - @SuppressWarnings("deprecation") // Forwarding to deprecated method - @Deprecated - @Override - public TrackGroupArray getCurrentTrackGroups() { - return player.getCurrentTrackGroups(); - } - - /** Calls {@link Player#getCurrentTrackSelections()} on the delegate and returns the result. */ - @SuppressWarnings("deprecation") // Forwarding to deprecated method - @Deprecated - @Override - public TrackSelectionArray getCurrentTrackSelections() { - return player.getCurrentTrackSelections(); - } - /** Calls {@link Player#getCurrentTracksInfo()} on the delegate and returns the result. */ @Override public TracksInfo getCurrentTracksInfo() { @@ -850,12 +832,6 @@ public class ForwardingPlayer implements Player { listener.onMediaItemTransition(mediaItem, reason); } - @Override - @SuppressWarnings("deprecation") - public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { - listener.onTracksChanged(trackGroups, trackSelections); - } - @Override public void onTracksInfoChanged(TracksInfo tracksInfo) { listener.onTracksInfoChanged(tracksInfo); 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 9297dfc763..8bb98894e1 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 @@ -33,10 +33,8 @@ import androidx.annotation.IntRange; import androidx.annotation.Nullable; import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.metadata.Metadata; -import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.trackselection.TrackSelection; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.util.BundleableUtil; import com.google.android.exoplayer2.util.FlagSet; @@ -670,23 +668,6 @@ public interface Player { default void onMediaItemTransition( @Nullable MediaItem mediaItem, @MediaItemTransitionReason int reason) {} - /** - * Called when the available or selected tracks change. - * - *

{@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 trackGroups The available tracks. Never null, but may be of length zero. - * @param trackSelections The selected tracks. Never null, but may contain null elements. A - * concrete implementation may include null elements if it has a fixed number of renderer - * components, wishes to report a TrackSelection for each of them, and has one or more - * renderer components that is not assigned any selected tracks. - * @deprecated Use {@link #onTracksInfoChanged(TracksInfo)} instead. - */ - @Deprecated - default void onTracksChanged( - TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {} - /** * Called when the available or selected tracks change. * @@ -2088,31 +2069,9 @@ public interface Player { void release(); /** - * Returns the available track groups. + * Returns information about the current tracks. * - * @see Listener#onTracksChanged(TrackGroupArray, TrackSelectionArray) - * @deprecated Use {@link #getCurrentTracksInfo()}. - */ - @Deprecated - TrackGroupArray getCurrentTrackGroups(); - - /** - * Returns the current track selections. - * - *

A concrete implementation may include null elements if it has a fixed number of renderer - * components, wishes to report a TrackSelection for each of them, and has one or more renderer - * components that is not assigned any selected tracks. - * - * @see Listener#onTracksChanged(TrackGroupArray, TrackSelectionArray) - * @deprecated Use {@link #getCurrentTracksInfo()}. - */ - @Deprecated - TrackSelectionArray getCurrentTrackSelections(); - - /** - * Returns the available tracks, as well as the tracks' support, type, and selection status. - * - * @see Listener#onTracksChanged(TrackGroupArray, TrackSelectionArray) + * @see Listener#onTracksInfoChanged(TracksInfo) */ TracksInfo getCurrentTracksInfo(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java index c8d1387962..7e98e3287b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java @@ -44,9 +44,11 @@ import com.google.android.exoplayer2.metadata.MetadataRenderer; import com.google.android.exoplayer2.source.DefaultMediaSourceFactory; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.ShuffleOrder; +import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.TextRenderer; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; +import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.DataSource; @@ -1143,6 +1145,25 @@ public interface ExoPlayer extends Player { @Nullable TrackSelector getTrackSelector(); + /** + * Returns the available track groups. + * + * @see Listener#onTracksInfoChanged(TracksInfo) + * @deprecated Use {@link #getCurrentTracksInfo()}. + */ + @Deprecated + TrackGroupArray getCurrentTrackGroups(); + + /** + * Returns the current track selections for each renderer, which may include {@code null} elements + * if some renderers do not have any selected tracks. + * + * @see Listener#onTracksInfoChanged(TracksInfo) + * @deprecated Use {@link #getCurrentTracksInfo()}. + */ + @Deprecated + TrackSelectionArray getCurrentTrackSelections(); + /** Returns the {@link Looper} associated with the playback thread. */ Looper getPlaybackLooper(); 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 d8edb6f1be..b618193d96 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 @@ -1880,11 +1880,6 @@ import java.util.concurrent.TimeoutException; } if (previousPlaybackInfo.trackSelectorResult != newPlaybackInfo.trackSelectorResult) { trackSelector.onSelectionActivated(newPlaybackInfo.trackSelectorResult.info); - TrackSelectionArray newSelection = - new TrackSelectionArray(newPlaybackInfo.trackSelectorResult.selections); - listeners.queueEvent( - Player.EVENT_TRACKS_CHANGED, - listener -> listener.onTracksChanged(newPlaybackInfo.trackGroups, newSelection)); listeners.queueEvent( Player.EVENT_TRACKS_CHANGED, listener -> listener.onTracksInfoChanged(newPlaybackInfo.trackSelectorResult.tracksInfo)); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/analytics/DefaultAnalyticsCollector.java b/library/core/src/main/java/com/google/android/exoplayer2/analytics/DefaultAnalyticsCollector.java index f8d78a32db..ea4cc7b0c9 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/analytics/DefaultAnalyticsCollector.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/analytics/DefaultAnalyticsCollector.java @@ -47,9 +47,7 @@ import com.google.android.exoplayer2.metadata.Metadata; 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.text.Cue; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.HandlerWrapper; @@ -482,13 +480,6 @@ public class DefaultAnalyticsCollector implements AnalyticsCollector { listener -> listener.onMediaItemTransition(eventTime, mediaItem, reason)); } - @SuppressWarnings("deprecation") // Implementing deprecated method. - @Override - public final void onTracksChanged( - TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { - // Do nothing. Handled by non-deprecated onTracksInfoChanged. - } - @Override public void onTracksInfoChanged(TracksInfo tracksInfo) { EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime(); 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 7462d672e1..9f27cd281d 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 @@ -96,6 +96,7 @@ import com.google.android.exoplayer2.Player.DiscontinuityReason; import com.google.android.exoplayer2.Player.Listener; import com.google.android.exoplayer2.Player.PositionInfo; import com.google.android.exoplayer2.Timeline.Window; +import com.google.android.exoplayer2.TracksInfo.TrackGroupInfo; import com.google.android.exoplayer2.analytics.AnalyticsListener; import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.drm.DrmSessionEventListener; @@ -143,7 +144,6 @@ import com.google.android.exoplayer2.testutil.FakeVideoRenderer; import com.google.android.exoplayer2.testutil.NoUidTimeline; import com.google.android.exoplayer2.testutil.TestExoPlayerBuilder; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.upstream.Allocation; import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Loader; @@ -267,8 +267,15 @@ public final class ExoPlayerTest { argThat(noUid(timeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE)); inOrder .verify(mockListener) - .onTracksChanged( - eq(new TrackGroupArray(new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT))), any()); + .onTracksInfoChanged( + eq( + new TracksInfo( + ImmutableList.of( + new TrackGroupInfo( + new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT), + /* adaptiveSupported= */ false, + new int[] {C.FORMAT_HANDLED}, + /* tracksSelected= */ new boolean[] {true}))))); inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt()); inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt()); assertThat(renderer.getFormatsRead()).containsExactly(ExoPlayerTestRunner.VIDEO_FORMAT); @@ -639,8 +646,15 @@ public final class ExoPlayerTest { argThat(noUid(thirdTimeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE)); inOrder .verify(mockPlayerListener) - .onTracksChanged( - eq(new TrackGroupArray(new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT))), any()); + .onTracksInfoChanged( + eq( + new TracksInfo( + ImmutableList.of( + new TrackGroupInfo( + new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT), + /* adaptiveSupported= */ false, + new int[] {C.FORMAT_HANDLED}, + /* tracksSelected= */ new boolean[] {true}))))); assertThat(renderer.isEnded).isTrue(); } @@ -774,12 +788,6 @@ public final class ExoPlayerTest { fakeMediaSource.setNewSourceInfo(adErrorTimeline); player.play(); runUntilPlaybackState(player, Player.STATE_ENDED); - Timeline.Window window = - player.getCurrentTimeline().getWindow(/* windowIndex= */ 0, new Timeline.Window()); - Timeline.Period period = - player - .getCurrentTimeline() - .getPeriod(/* periodIndex= */ 0, new Timeline.Period(), /* setIds= */ true); player.release(); // Content to content transition is ignored. @@ -3408,8 +3416,7 @@ public final class ExoPlayerTest { .waitForPendingPlayerCommands() .play() .build(); - List trackGroupsList = new ArrayList<>(); - List trackSelectionsList = new ArrayList<>(); + List tracksInfoList = new ArrayList<>(); new ExoPlayerTestRunner.Builder(context) .setMediaSources(mediaSource) .setSupportedFormats(ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT) @@ -3417,25 +3424,21 @@ public final class ExoPlayerTest { .setPlayerListener( new Player.Listener() { @Override - public void onTracksChanged( - TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { - trackGroupsList.add(trackGroups); - trackSelectionsList.add(trackSelections); + public void onTracksInfoChanged(TracksInfo tracksInfo) { + tracksInfoList.add(tracksInfo); } }) .build() .start() .blockUntilEnded(TIMEOUT_MS); - assertThat(trackGroupsList).hasSize(3); + assertThat(tracksInfoList).hasSize(3); // First track groups of the 1st period are reported. - // Then the seek to an unprepared period will result in empty track groups and selections being - // returned. + // Then the seek to an unprepared period will result in empty track groups being returned. // Then the track groups of the 2nd period are reported. - assertThat(trackGroupsList.get(0).get(0).getFormat(0)) + assertThat(tracksInfoList.get(0).getTrackGroupInfos().get(0).getTrackFormat(0)) .isEqualTo(ExoPlayerTestRunner.VIDEO_FORMAT); - assertThat(trackGroupsList.get(1)).isEqualTo(TrackGroupArray.EMPTY); - assertThat(trackSelectionsList.get(1).get(0)).isNull(); - assertThat(trackGroupsList.get(2).get(0).getFormat(0)) + assertThat(tracksInfoList.get(1)).isEqualTo(TracksInfo.EMPTY); + assertThat(tracksInfoList.get(2).getTrackGroupInfos().get(0).getTrackFormat(0)) .isEqualTo(ExoPlayerTestRunner.AUDIO_FORMAT); } @@ -7981,7 +7984,6 @@ public final class ExoPlayerTest { }; AtomicReference timelineAfterError = new AtomicReference<>(); AtomicReference trackInfosAfterError = new AtomicReference<>(); - AtomicReference trackSelectionsAfterError = new AtomicReference<>(); AtomicInteger mediaItemIndexAfterError = new AtomicInteger(); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) @@ -7995,7 +7997,6 @@ public final class ExoPlayerTest { public void onPlayerError(EventTime eventTime, PlaybackException error) { timelineAfterError.set(player.getCurrentTimeline()); trackInfosAfterError.set(player.getCurrentTracksInfo()); - trackSelectionsAfterError.set(player.getCurrentTrackSelections()); mediaItemIndexAfterError.set(player.getCurrentMediaItemIndex()); } }); @@ -8027,8 +8028,8 @@ public final class ExoPlayerTest { assertThat(trackInfosAfterError.get().getTrackGroupInfos()).hasSize(1); assertThat(trackInfosAfterError.get().getTrackGroupInfos().get(0).getTrackFormat(0)) .isEqualTo(ExoPlayerTestRunner.AUDIO_FORMAT); - assertThat(trackSelectionsAfterError.get().get(0)).isNull(); // Video renderer. - assertThat(trackSelectionsAfterError.get().get(1)).isNotNull(); // Audio renderer. + assertThat(trackInfosAfterError.get().isTypeSelected(C.TRACK_TYPE_VIDEO)).isFalse(); + assertThat(trackInfosAfterError.get().isTypeSelected(C.TRACK_TYPE_AUDIO)).isTrue(); } @Test @@ -10412,7 +10413,7 @@ public final class ExoPlayerTest { verify(listener, atLeastOnce()).onShuffleModeEnabledChanged(anyBoolean()); verify(listener, atLeastOnce()).onPlaybackStateChanged(anyInt()); verify(listener, atLeastOnce()).onIsLoadingChanged(anyBoolean()); - verify(listener, atLeastOnce()).onTracksChanged(any(), any()); + verify(listener, atLeastOnce()).onTracksInfoChanged(any()); verify(listener, atLeastOnce()).onMediaMetadataChanged(any()); verify(listener, atLeastOnce()).onPlayWhenReadyChanged(anyBoolean(), anyInt()); verify(listener, atLeastOnce()).onIsPlayingChanged(anyBoolean()); 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 32a053cfcb..abdc63a428 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 @@ -30,6 +30,8 @@ import com.google.android.exoplayer2.audio.AuxEffectInfo; import com.google.android.exoplayer2.decoder.DecoderCounters; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.ShuffleOrder; +import com.google.android.exoplayer2.source.TrackGroupArray; +import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.PriorityTaskManager; @@ -292,6 +294,16 @@ public class StubExoPlayer extends StubPlayer implements ExoPlayer { throw new UnsupportedOperationException(); } + @Override + public TrackGroupArray getCurrentTrackGroups() { + throw new UnsupportedOperationException(); + } + + @Override + public TrackSelectionArray getCurrentTrackSelections() { + throw new UnsupportedOperationException(); + } + @Override public void setForegroundMode(boolean foregroundMode) { throw new UnsupportedOperationException(); diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubPlayer.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubPlayer.java index b1da2a93f2..b896b11f3f 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubPlayer.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/StubPlayer.java @@ -31,9 +31,7 @@ import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.TracksInfo; import com.google.android.exoplayer2.audio.AudioAttributes; -import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.text.Cue; -import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.video.VideoSize; import java.util.List; @@ -190,16 +188,6 @@ public class StubPlayer extends BasePlayer { throw new UnsupportedOperationException(); } - @Override - public TrackGroupArray getCurrentTrackGroups() { - throw new UnsupportedOperationException(); - } - - @Override - public TrackSelectionArray getCurrentTrackSelections() { - throw new UnsupportedOperationException(); - } - @Override public TracksInfo getCurrentTracksInfo() { throw new UnsupportedOperationException();