From 7de079493cf039b529c526b105d9289747660c90 Mon Sep 17 00:00:00 2001 From: ibaker Date: Tue, 2 Nov 2021 10:27:56 +0000 Subject: [PATCH 1/3] Migrate usages of Window-based Player methods Where this introduced an inconsistency (e.g. assigning to something called `windowIndex`), I generally renamed the transitive closure of identifiers to maintain consistency (meaning this change is quite large). The exception is code that interacts with Timeline and Window directly, where sometimes I kept the 'window' nomenclature. #minor-release PiperOrigin-RevId: 407040052 --- RELEASENOTES.md | 4 + .../exoplayer2/castdemo/PlayerManager.java | 12 +- .../exoplayer2/demo/PlayerActivity.java | 16 +- .../exoplayer2/ext/cast/CastPlayer.java | 18 +- .../exoplayer2/ext/ima/FakeExoPlayer.java | 2 +- .../ext/leanback/LeanbackPlayerAdapter.java | 2 +- .../exoplayer2/ext/media2/PlayerWrapper.java | 16 +- .../mediasession/MediaSessionConnector.java | 29 +- .../mediasession/TimelineQueueNavigator.java | 38 +- .../google/android/exoplayer2/BasePlayer.java | 49 +- .../google/android/exoplayer2/ExoPlayer.java | 23 +- .../android/exoplayer2/ExoPlayerImpl.java | 43 +- .../exoplayer2/ExoPlayerImplInternal.java | 2 +- .../android/exoplayer2/PlayerMessage.java | 49 +- .../android/exoplayer2/SimpleExoPlayer.java | 6 +- .../analytics/AnalyticsCollector.java | 6 +- .../analytics/AnalyticsListener.java | 10 +- .../exoplayer2/util/DebugTextViewHelper.java | 4 +- .../android/exoplayer2/ExoPlayerTest.java | 1003 +++++++++-------- .../exoplayer2/ui/PlayerControlView.java | 6 +- .../ui/PlayerNotificationManager.java | 10 +- .../android/exoplayer2/ui/PlayerView.java | 4 +- .../ui/StyledPlayerControlView.java | 7 +- .../exoplayer2/ui/StyledPlayerView.java | 4 +- .../robolectric/TestPlayerRunHelper.java | 17 +- .../android/exoplayer2/testutil/Action.java | 61 +- .../exoplayer2/testutil/ActionSchedule.java | 67 +- .../testutil/ExoPlayerTestRunner.java | 22 +- .../exoplayer2/testutil/StubExoPlayer.java | 2 +- 29 files changed, 788 insertions(+), 744 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index bf708bfa32..0d8bf3fdb5 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -85,6 +85,10 @@ * RTMP extension: * Upgrade to `io.antmedia:rtmp_client`, which does not rely on `jcenter()` ([#9591](https://github.com/google/ExoPlayer/issues/9591)). +* MediaSession extension: + * Rename + `MediaSessionConnector.QueueNavigator#onCurrentWindowIndexChanged` to + `onCurrentMediaItemIndexChanged`. * Remove deprecated symbols: * Remove `Renderer.VIDEO_SCALING_MODE_*` constants. Use identically named constants in `C` instead. diff --git a/demos/cast/src/main/java/com/google/android/exoplayer2/castdemo/PlayerManager.java b/demos/cast/src/main/java/com/google/android/exoplayer2/castdemo/PlayerManager.java index 9e66c823a0..54174b0c53 100644 --- a/demos/cast/src/main/java/com/google/android/exoplayer2/castdemo/PlayerManager.java +++ b/demos/cast/src/main/java/com/google/android/exoplayer2/castdemo/PlayerManager.java @@ -261,7 +261,7 @@ import java.util.ArrayList; int playbackState = currentPlayer.getPlaybackState(); maybeSetCurrentItemAndNotify( playbackState != Player.STATE_IDLE && playbackState != Player.STATE_ENDED - ? currentPlayer.getCurrentWindowIndex() + ? currentPlayer.getCurrentMediaItemIndex() : C.INDEX_UNSET); } @@ -281,7 +281,7 @@ import java.util.ArrayList; // Player state management. long playbackPositionMs = C.TIME_UNSET; - int windowIndex = C.INDEX_UNSET; + int currentItemIndex = C.INDEX_UNSET; boolean playWhenReady = false; Player previousPlayer = this.currentPlayer; @@ -291,10 +291,10 @@ import java.util.ArrayList; if (playbackState != Player.STATE_ENDED) { playbackPositionMs = previousPlayer.getCurrentPosition(); playWhenReady = previousPlayer.getPlayWhenReady(); - windowIndex = previousPlayer.getCurrentWindowIndex(); - if (windowIndex != currentItemIndex) { + currentItemIndex = previousPlayer.getCurrentMediaItemIndex(); + if (currentItemIndex != this.currentItemIndex) { playbackPositionMs = C.TIME_UNSET; - windowIndex = currentItemIndex; + currentItemIndex = this.currentItemIndex; } } previousPlayer.stop(); @@ -304,7 +304,7 @@ import java.util.ArrayList; this.currentPlayer = currentPlayer; // Media queue management. - currentPlayer.setMediaItems(mediaQueue, windowIndex, playbackPositionMs); + currentPlayer.setMediaItems(mediaQueue, currentItemIndex, playbackPositionMs); currentPlayer.setPlayWhenReady(playWhenReady); currentPlayer.prepare(); } diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java index e080c23f99..ca9fd45d42 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java @@ -65,7 +65,7 @@ public class PlayerActivity extends AppCompatActivity // Saved instance state keys. private static final String KEY_TRACK_SELECTION_PARAMETERS = "track_selection_parameters"; - private static final String KEY_WINDOW = "window"; + private static final String KEY_ITEM_INDEX = "item_index"; private static final String KEY_POSITION = "position"; private static final String KEY_AUTO_PLAY = "auto_play"; @@ -83,7 +83,7 @@ public class PlayerActivity extends AppCompatActivity private DebugTextViewHelper debugViewHelper; private TracksInfo lastSeenTracksInfo; private boolean startAutoPlay; - private int startWindow; + private int startItemIndex; private long startPosition; // For ad playback only. @@ -114,7 +114,7 @@ public class PlayerActivity extends AppCompatActivity DefaultTrackSelector.Parameters.CREATOR.fromBundle( savedInstanceState.getBundle(KEY_TRACK_SELECTION_PARAMETERS)); startAutoPlay = savedInstanceState.getBoolean(KEY_AUTO_PLAY); - startWindow = savedInstanceState.getInt(KEY_WINDOW); + startItemIndex = savedInstanceState.getInt(KEY_ITEM_INDEX); startPosition = savedInstanceState.getLong(KEY_POSITION); } else { trackSelectionParameters = @@ -206,7 +206,7 @@ public class PlayerActivity extends AppCompatActivity updateStartPosition(); outState.putBundle(KEY_TRACK_SELECTION_PARAMETERS, trackSelectionParameters.toBundle()); outState.putBoolean(KEY_AUTO_PLAY, startAutoPlay); - outState.putInt(KEY_WINDOW, startWindow); + outState.putInt(KEY_ITEM_INDEX, startItemIndex); outState.putLong(KEY_POSITION, startPosition); } @@ -282,9 +282,9 @@ public class PlayerActivity extends AppCompatActivity debugViewHelper = new DebugTextViewHelper(player, debugTextView); debugViewHelper.start(); } - boolean haveStartPosition = startWindow != C.INDEX_UNSET; + boolean haveStartPosition = startItemIndex != C.INDEX_UNSET; if (haveStartPosition) { - player.seekTo(startWindow, startPosition); + player.seekTo(startItemIndex, startPosition); } player.setMediaItems(mediaItems, /* resetPosition= */ !haveStartPosition); player.prepare(); @@ -382,14 +382,14 @@ public class PlayerActivity extends AppCompatActivity private void updateStartPosition() { if (player != null) { startAutoPlay = player.getPlayWhenReady(); - startWindow = player.getCurrentWindowIndex(); + startItemIndex = player.getCurrentMediaItemIndex(); startPosition = Math.max(0, player.getContentPosition()); } } protected void clearStartPosition() { startAutoPlay = true; - startWindow = C.INDEX_UNSET; + startItemIndex = C.INDEX_UNSET; startPosition = C.TIME_UNSET; } 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 1bf2cd410b..0054378727 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 @@ -318,9 +318,9 @@ public final class CastPlayer extends BasePlayer { @Override public void setMediaItems(List mediaItems, boolean resetPosition) { - int windowIndex = resetPosition ? 0 : getCurrentWindowIndex(); + int mediaItemIndex = resetPosition ? 0 : getCurrentMediaItemIndex(); long startPositionMs = resetPosition ? C.TIME_UNSET : getContentPosition(); - setMediaItems(mediaItems, windowIndex, startPositionMs); + setMediaItems(mediaItems, mediaItemIndex, startPositionMs); } @Override @@ -443,7 +443,7 @@ public final class CastPlayer extends BasePlayer { // in RemoteMediaClient. positionMs = positionMs != C.TIME_UNSET ? positionMs : 0; if (mediaStatus != null) { - if (getCurrentWindowIndex() != mediaItemIndex) { + if (getCurrentMediaItemIndex() != mediaItemIndex) { remoteMediaClient .queueJumpToItem( (int) currentTimeline.getPeriod(mediaItemIndex, period).uid, positionMs, null) @@ -636,7 +636,7 @@ public final class CastPlayer extends BasePlayer { @Override public int getCurrentPeriodIndex() { - return getCurrentWindowIndex(); + return getCurrentMediaItemIndex(); } @Override @@ -1103,15 +1103,15 @@ public final class CastPlayer extends BasePlayer { @Nullable private PendingResult setMediaItemsInternal( MediaQueueItem[] mediaQueueItems, - int startWindowIndex, + int startIndex, long startPositionMs, @RepeatMode int repeatMode) { if (remoteMediaClient == null || mediaQueueItems.length == 0) { return null; } startPositionMs = startPositionMs == C.TIME_UNSET ? 0 : startPositionMs; - if (startWindowIndex == C.INDEX_UNSET) { - startWindowIndex = getCurrentWindowIndex(); + if (startIndex == C.INDEX_UNSET) { + startIndex = getCurrentMediaItemIndex(); startPositionMs = getCurrentPosition(); } Timeline currentTimeline = getCurrentTimeline(); @@ -1120,7 +1120,7 @@ public final class CastPlayer extends BasePlayer { } return remoteMediaClient.queueLoad( mediaQueueItems, - min(startWindowIndex, mediaQueueItems.length - 1), + min(startIndex, mediaQueueItems.length - 1), getCastRepeatMode(repeatMode), startPositionMs, /* customData= */ null); @@ -1180,7 +1180,7 @@ public final class CastPlayer extends BasePlayer { } return new PositionInfo( newWindowUid, - getCurrentWindowIndex(), + getCurrentMediaItemIndex(), newMediaItem, newPeriodUid, getCurrentPeriodIndex(), diff --git a/extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/FakeExoPlayer.java b/extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/FakeExoPlayer.java index fb2975920d..90e2087389 100644 --- a/extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/FakeExoPlayer.java +++ b/extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/FakeExoPlayer.java @@ -279,7 +279,7 @@ import com.google.android.exoplayer2.util.Util; timeline.getPeriod(0, period).getAdDurationUs(adGroupIndex, adIndexInAdGroup); return Util.usToMs(adDurationUs); } else { - return timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); + return timeline.getWindow(getCurrentMediaItemIndex(), window).getDurationMs(); } } diff --git a/extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java b/extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java index a914869f8f..bd70d14394 100644 --- a/extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java +++ b/extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java @@ -141,7 +141,7 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab if (player.getPlaybackState() == Player.STATE_IDLE) { player.prepare(); } else if (player.getPlaybackState() == Player.STATE_ENDED) { - player.seekToDefaultPosition(player.getCurrentWindowIndex()); + player.seekToDefaultPosition(player.getCurrentMediaItemIndex()); } if (player.isCommandAvailable(Player.COMMAND_PLAY_PAUSE)) { player.play(); diff --git a/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java b/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java index 7891bc47f3..f69f725edb 100644 --- a/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java +++ b/extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java @@ -253,8 +253,8 @@ import java.util.List; // checkIndex() throws IndexOutOfBoundsException which maps the RESULT_ERROR_BAD_VALUE // but RESULT_ERROR_INVALID_STATE with IllegalStateException is expected here. Assertions.checkState(0 <= index && index < timeline.getWindowCount()); - int windowIndex = player.getCurrentWindowIndex(); - if (windowIndex == index || !player.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)) { + int currentIndex = player.getCurrentMediaItemIndex(); + if (currentIndex == index || !player.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)) { return false; } player.seekToDefaultPosition(index); @@ -301,7 +301,7 @@ import java.util.List; } public int getCurrentMediaItemIndex() { - return media2Playlist.isEmpty() ? C.INDEX_UNSET : player.getCurrentWindowIndex(); + return media2Playlist.isEmpty() ? C.INDEX_UNSET : player.getCurrentMediaItemIndex(); } public int getPreviousMediaItemIndex() { @@ -331,7 +331,7 @@ import java.util.List; if (!player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)) { return false; } - player.seekTo(player.getCurrentWindowIndex(), /* positionMs= */ 0); + player.seekTo(player.getCurrentMediaItemIndex(), /* positionMs= */ 0); } boolean playWhenReady = player.getPlayWhenReady(); int suppressReason = player.getPlaybackSuppressionReason(); @@ -358,7 +358,7 @@ import java.util.List; if (!player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM)) { return false; } - player.seekTo(player.getCurrentWindowIndex(), position); + player.seekTo(player.getCurrentMediaItemIndex(), position); return true; } @@ -493,7 +493,7 @@ import java.util.List; public boolean isCurrentMediaItemSeekable() { return getCurrentMediaItem() != null && !player.isPlayingAd() - && player.isCurrentWindowSeekable(); + && player.isCurrentMediaItemSeekable(); } public boolean canSkipToPlaylistItem() { @@ -502,11 +502,11 @@ import java.util.List; } public boolean canSkipToPreviousPlaylistItem() { - return player.hasPreviousWindow(); + return player.hasPreviousMediaItem(); } public boolean canSkipToNextPlaylistItem() { - return player.hasNextWindow(); + return player.hasNextMediaItem(); } public boolean hasError() { diff --git a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java index b823d0f90f..cfda09ff0a 100644 --- a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java +++ b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java @@ -263,12 +263,13 @@ public final class MediaSessionConnector { * @param player The player connected to the media session. */ void onTimelineChanged(Player player); + /** - * Called when the current window index changed. + * Called when the current media item index changed. * * @param player The player connected to the media session. */ - void onCurrentWindowIndexChanged(Player player); + default void onCurrentMediaItemIndexChanged(Player player) {} /** * Gets the id of the currently active queue item, or {@link * MediaSessionCompat.QueueItem#UNKNOWN_ID} if the active item is unknown. @@ -969,8 +970,8 @@ public final class MediaSessionConnector { return player != null && mediaButtonEventHandler != null; } - private void seekTo(Player player, int windowIndex, long positionMs) { - player.seekTo(windowIndex, positionMs); + private void seekTo(Player player, int mediaItemIndex, long positionMs) { + player.seekTo(mediaItemIndex, positionMs); } private static int getMediaSessionPlaybackState( @@ -1023,7 +1024,7 @@ public final class MediaSessionConnector { } builder.putLong( MediaMetadataCompat.METADATA_KEY_DURATION, - player.isCurrentWindowDynamic() || player.getDuration() == C.TIME_UNSET + player.isCurrentMediaItemDynamic() || player.getDuration() == C.TIME_UNSET ? -1 : player.getDuration()); long activeQueueItemId = mediaController.getPlaybackState().getActiveQueueItemId(); @@ -1097,7 +1098,7 @@ public final class MediaSessionConnector { private class ComponentListener extends MediaSessionCompat.Callback implements Player.Listener { - private int currentWindowIndex; + private int currentMediaItemIndex; private int currentWindowCount; // Player.Listener implementation. @@ -1107,9 +1108,9 @@ public final class MediaSessionConnector { boolean invalidatePlaybackState = false; boolean invalidateMetadata = false; if (events.contains(Player.EVENT_POSITION_DISCONTINUITY)) { - if (currentWindowIndex != player.getCurrentWindowIndex()) { + if (currentMediaItemIndex != player.getCurrentMediaItemIndex()) { if (queueNavigator != null) { - queueNavigator.onCurrentWindowIndexChanged(player); + queueNavigator.onCurrentMediaItemIndexChanged(player); } invalidateMetadata = true; } @@ -1118,11 +1119,11 @@ public final class MediaSessionConnector { if (events.contains(Player.EVENT_TIMELINE_CHANGED)) { int windowCount = player.getCurrentTimeline().getWindowCount(); - int windowIndex = player.getCurrentWindowIndex(); + int mediaItemIndex = player.getCurrentMediaItemIndex(); if (queueNavigator != null) { queueNavigator.onTimelineChanged(player); invalidatePlaybackState = true; - } else if (currentWindowCount != windowCount || currentWindowIndex != windowIndex) { + } else if (currentWindowCount != windowCount || currentMediaItemIndex != mediaItemIndex) { // active queue item and queue navigation actions may need to be updated invalidatePlaybackState = true; } @@ -1130,8 +1131,8 @@ public final class MediaSessionConnector { invalidateMetadata = true; } - // Update currentWindowIndex after comparisons above. - currentWindowIndex = player.getCurrentWindowIndex(); + // Update currentMediaItemIndex after comparisons above. + currentMediaItemIndex = player.getCurrentMediaItemIndex(); if (events.containsAny( EVENT_PLAYBACK_STATE_CHANGED, @@ -1170,7 +1171,7 @@ public final class MediaSessionConnector { player.prepare(); } } else if (player.getPlaybackState() == Player.STATE_ENDED) { - seekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); + seekTo(player, player.getCurrentMediaItemIndex(), C.TIME_UNSET); } Assertions.checkNotNull(player).play(); } @@ -1186,7 +1187,7 @@ public final class MediaSessionConnector { @Override public void onSeekTo(long positionMs) { if (canDispatchPlaybackAction(PlaybackStateCompat.ACTION_SEEK_TO)) { - seekTo(player, player.getCurrentWindowIndex(), positionMs); + seekTo(player, player.getCurrentMediaItemIndex(), positionMs); } } diff --git a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/TimelineQueueNavigator.java b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/TimelineQueueNavigator.java index 90db27e458..4277de3c32 100644 --- a/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/TimelineQueueNavigator.java +++ b/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/TimelineQueueNavigator.java @@ -98,7 +98,7 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu boolean enableNext = false; Timeline timeline = player.getCurrentTimeline(); if (!timeline.isEmpty() && !player.isPlayingAd()) { - timeline.getWindow(player.getCurrentWindowIndex(), window); + timeline.getWindow(player.getCurrentMediaItemIndex(), window); enableSkipTo = timeline.getWindowCount() > 1; enablePrevious = player.isCommandAvailable(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM) @@ -128,12 +128,12 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu } @Override - public final void onCurrentWindowIndexChanged(Player player) { + public final void onCurrentMediaItemIndexChanged(Player player) { if (activeQueueItemId == MediaSessionCompat.QueueItem.UNKNOWN_ID || player.getCurrentTimeline().getWindowCount() > maxQueueSize) { publishFloatingQueueWindow(player); } else if (!player.getCurrentTimeline().isEmpty()) { - activeQueueItemId = player.getCurrentWindowIndex(); + activeQueueItemId = player.getCurrentMediaItemIndex(); } } @@ -185,40 +185,40 @@ public abstract class TimelineQueueNavigator implements MediaSessionConnector.Qu int queueSize = min(maxQueueSize, timeline.getWindowCount()); // Add the active queue item. - int currentWindowIndex = player.getCurrentWindowIndex(); + int currentMediaItemIndex = player.getCurrentMediaItemIndex(); queue.add( new MediaSessionCompat.QueueItem( - getMediaDescription(player, currentWindowIndex), currentWindowIndex)); + getMediaDescription(player, currentMediaItemIndex), currentMediaItemIndex)); // Fill queue alternating with next and/or previous queue items. - int firstWindowIndex = currentWindowIndex; - int lastWindowIndex = currentWindowIndex; + int firstMediaItemIndex = currentMediaItemIndex; + int lastMediaItemIndex = currentMediaItemIndex; boolean shuffleModeEnabled = player.getShuffleModeEnabled(); - while ((firstWindowIndex != C.INDEX_UNSET || lastWindowIndex != C.INDEX_UNSET) + while ((firstMediaItemIndex != C.INDEX_UNSET || lastMediaItemIndex != C.INDEX_UNSET) && queue.size() < queueSize) { // Begin with next to have a longer tail than head if an even sized queue needs to be trimmed. - if (lastWindowIndex != C.INDEX_UNSET) { - lastWindowIndex = + if (lastMediaItemIndex != C.INDEX_UNSET) { + lastMediaItemIndex = timeline.getNextWindowIndex( - lastWindowIndex, Player.REPEAT_MODE_OFF, shuffleModeEnabled); - if (lastWindowIndex != C.INDEX_UNSET) { + lastMediaItemIndex, Player.REPEAT_MODE_OFF, shuffleModeEnabled); + if (lastMediaItemIndex != C.INDEX_UNSET) { queue.add( new MediaSessionCompat.QueueItem( - getMediaDescription(player, lastWindowIndex), lastWindowIndex)); + getMediaDescription(player, lastMediaItemIndex), lastMediaItemIndex)); } } - if (firstWindowIndex != C.INDEX_UNSET && queue.size() < queueSize) { - firstWindowIndex = + if (firstMediaItemIndex != C.INDEX_UNSET && queue.size() < queueSize) { + firstMediaItemIndex = timeline.getPreviousWindowIndex( - firstWindowIndex, Player.REPEAT_MODE_OFF, shuffleModeEnabled); - if (firstWindowIndex != C.INDEX_UNSET) { + firstMediaItemIndex, Player.REPEAT_MODE_OFF, shuffleModeEnabled); + if (firstMediaItemIndex != C.INDEX_UNSET) { queue.addFirst( new MediaSessionCompat.QueueItem( - getMediaDescription(player, firstWindowIndex), firstWindowIndex)); + getMediaDescription(player, firstMediaItemIndex), firstMediaItemIndex)); } } } mediaSession.setQueue(new ArrayList<>(queue)); - activeQueueItemId = currentWindowIndex; + activeQueueItemId = currentMediaItemIndex; } } diff --git a/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java b/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java index b60e4a3a7e..2209803f3e 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/BasePlayer.java @@ -118,7 +118,7 @@ public abstract class BasePlayer implements Player { @Override public final void seekToDefaultPosition() { - seekToDefaultPosition(getCurrentWindowIndex()); + seekToDefaultPosition(getCurrentMediaItemIndex()); } @Override @@ -128,7 +128,7 @@ public abstract class BasePlayer implements Player { @Override public final void seekTo(long positionMs) { - seekTo(getCurrentWindowIndex(), positionMs); + seekTo(getCurrentMediaItemIndex(), positionMs); } @Override @@ -184,13 +184,13 @@ public abstract class BasePlayer implements Player { if (timeline.isEmpty() || isPlayingAd()) { return; } - boolean hasPreviousWindow = hasPreviousWindow(); - if (isCurrentWindowLive() && !isCurrentWindowSeekable()) { - if (hasPreviousWindow) { - seekToPreviousWindow(); + boolean hasPreviousMediaItem = hasPreviousMediaItem(); + if (isCurrentMediaItemLive() && !isCurrentMediaItemSeekable()) { + if (hasPreviousMediaItem) { + seekToPreviousMediaItem(); } - } else if (hasPreviousWindow && getCurrentPosition() <= getMaxSeekToPreviousPosition()) { - seekToPreviousWindow(); + } else if (hasPreviousMediaItem && getCurrentPosition() <= getMaxSeekToPreviousPosition()) { + seekToPreviousMediaItem(); } else { seekTo(/* positionMs= */ 0); } @@ -239,9 +239,9 @@ public abstract class BasePlayer implements Player { if (timeline.isEmpty() || isPlayingAd()) { return; } - if (hasNextWindow()) { - seekToNextWindow(); - } else if (isCurrentWindowLive() && isCurrentWindowDynamic()) { + if (hasNextMediaItem()) { + seekToNextMediaItem(); + } else if (isCurrentMediaItemLive() && isCurrentMediaItemDynamic()) { seekToDefaultPosition(); } } @@ -293,7 +293,7 @@ public abstract class BasePlayer implements Player { Timeline timeline = getCurrentTimeline(); return timeline.isEmpty() ? null - : timeline.getWindow(getCurrentWindowIndex(), window).mediaItem; + : timeline.getWindow(getCurrentMediaItemIndex(), window).mediaItem; } @Override @@ -310,7 +310,9 @@ public abstract class BasePlayer implements Player { @Nullable public final Object getCurrentManifest() { Timeline timeline = getCurrentTimeline(); - return timeline.isEmpty() ? null : timeline.getWindow(getCurrentWindowIndex(), window).manifest; + return timeline.isEmpty() + ? null + : timeline.getWindow(getCurrentMediaItemIndex(), window).manifest; } @Override @@ -352,7 +354,8 @@ public abstract class BasePlayer implements Player { if (timeline.isEmpty()) { return C.TIME_UNSET; } - long windowStartTimeMs = timeline.getWindow(getCurrentWindowIndex(), window).windowStartTimeMs; + long windowStartTimeMs = + timeline.getWindow(getCurrentMediaItemIndex(), window).windowStartTimeMs; if (windowStartTimeMs == C.TIME_UNSET) { return C.TIME_UNSET; } @@ -376,7 +379,7 @@ public abstract class BasePlayer implements Player { Timeline timeline = getCurrentTimeline(); return timeline.isEmpty() ? C.TIME_UNSET - : timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); + : timeline.getWindow(getCurrentMediaItemIndex(), window).getDurationMs(); } /** @@ -389,22 +392,24 @@ public abstract class BasePlayer implements Player { return new Commands.Builder() .addAll(permanentAvailableCommands) .addIf(COMMAND_SEEK_TO_DEFAULT_POSITION, !isPlayingAd()) - .addIf(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, isCurrentWindowSeekable() && !isPlayingAd()) - .addIf(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, hasPreviousWindow() && !isPlayingAd()) + .addIf(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, isCurrentMediaItemSeekable() && !isPlayingAd()) + .addIf(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, hasPreviousMediaItem() && !isPlayingAd()) .addIf( COMMAND_SEEK_TO_PREVIOUS, !getCurrentTimeline().isEmpty() - && (hasPreviousWindow() || !isCurrentWindowLive() || isCurrentWindowSeekable()) + && (hasPreviousMediaItem() + || !isCurrentMediaItemLive() + || isCurrentMediaItemSeekable()) && !isPlayingAd()) - .addIf(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, hasNextWindow() && !isPlayingAd()) + .addIf(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, hasNextMediaItem() && !isPlayingAd()) .addIf( COMMAND_SEEK_TO_NEXT, !getCurrentTimeline().isEmpty() - && (hasNextWindow() || (isCurrentWindowLive() && isCurrentWindowDynamic())) + && (hasNextMediaItem() || (isCurrentMediaItemLive() && isCurrentMediaItemDynamic())) && !isPlayingAd()) .addIf(COMMAND_SEEK_TO_MEDIA_ITEM, !isPlayingAd()) - .addIf(COMMAND_SEEK_BACK, isCurrentWindowSeekable() && !isPlayingAd()) - .addIf(COMMAND_SEEK_FORWARD, isCurrentWindowSeekable() && !isPlayingAd()) + .addIf(COMMAND_SEEK_BACK, isCurrentMediaItemSeekable() && !isPlayingAd()) + .addIf(COMMAND_SEEK_FORWARD, isCurrentMediaItemSeekable() && !isPlayingAd()) .build(); } 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 e594883c72..2143d2a1fb 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 @@ -1126,7 +1126,7 @@ public interface ExoPlayer extends Player { * @param mediaSources The new {@link MediaSource MediaSources}. * @param resetPosition Whether the playback position should be reset to the default position in * the first {@link Timeline.Window}. If false, playback will start from the position defined - * by {@link #getCurrentWindowIndex()} and {@link #getCurrentPosition()}. + * by {@link #getCurrentMediaItemIndex()} and {@link #getCurrentPosition()}. */ void setMediaSources(List mediaSources, boolean resetPosition); @@ -1134,14 +1134,15 @@ public interface ExoPlayer extends Player { * Clears the playlist and adds the specified {@link MediaSource MediaSources}. * * @param mediaSources The new {@link MediaSource MediaSources}. - * @param startWindowIndex The window index to start playback from. If {@link C#INDEX_UNSET} is - * passed, the current position is not reset. + * @param startMediaItemIndex The media item index to start playback from. If {@link + * C#INDEX_UNSET} is passed, the current position is not reset. * @param startPositionMs The position in milliseconds to start playback from. If {@link - * C#TIME_UNSET} is passed, the default position of the given window is used. In any case, if - * {@code startWindowIndex} is set to {@link C#INDEX_UNSET}, this parameter is ignored and the - * position is not reset at all. + * C#TIME_UNSET} is passed, the default position of the given media item is used. In any case, + * if {@code startMediaItemIndex} is set to {@link C#INDEX_UNSET}, this parameter is ignored + * and the position is not reset at all. */ - void setMediaSources(List mediaSources, int startWindowIndex, long startPositionMs); + void setMediaSources( + List mediaSources, int startMediaItemIndex, long startPositionMs); /** * Clears the playlist, adds the specified {@link MediaSource} and resets the position to the @@ -1164,7 +1165,7 @@ public interface ExoPlayer extends Player { * * @param mediaSource The new {@link MediaSource}. * @param resetPosition Whether the playback position should be reset to the default position. If - * false, playback will start from the position defined by {@link #getCurrentWindowIndex()} + * false, playback will start from the position defined by {@link #getCurrentMediaItemIndex()} * and {@link #getCurrentPosition()}. */ void setMediaSource(MediaSource mediaSource, boolean resetPosition); @@ -1331,9 +1332,9 @@ public interface ExoPlayer extends Player { * will be delivered immediately without blocking on the playback thread. The default {@link * PlayerMessage#getType()} is 0 and the default {@link PlayerMessage#getPayload()} is null. If a * position is specified with {@link PlayerMessage#setPosition(long)}, the message will be - * delivered at this position in the current window defined by {@link #getCurrentWindowIndex()}. - * Alternatively, the message can be sent at a specific window using {@link - * PlayerMessage#setPosition(int, long)}. + * delivered at this position in the current media item defined by {@link + * #getCurrentMediaItemIndex()}. Alternatively, the message can be sent at a specific mediaItem + * using {@link PlayerMessage#setPosition(int, long)}. */ PlayerMessage createMessage(PlayerMessage.Target target); 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 653135e59c..61a1d41b82 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 @@ -537,7 +537,7 @@ import java.util.concurrent.CopyOnWriteArraySet; playbackInfo, timeline, getPeriodPositionOrMaskWindowPosition( - timeline, getCurrentWindowIndex(), getCurrentPosition())); + timeline, getCurrentMediaItemIndex(), getCurrentPosition())); pendingOperationAcks++; this.shuffleOrder = shuffleOrder; internalPlayer.setShuffleOrder(shuffleOrder); @@ -662,7 +662,7 @@ import java.util.concurrent.CopyOnWriteArraySet; @Player.State int newPlaybackState = getPlaybackState() == Player.STATE_IDLE ? Player.STATE_IDLE : Player.STATE_BUFFERING; - int oldMaskingWindowIndex = getCurrentWindowIndex(); + int oldMaskingMediaItemIndex = getCurrentMediaItemIndex(); PlaybackInfo newPlaybackInfo = playbackInfo.copyWithPlaybackState(newPlaybackState); newPlaybackInfo = maskTimelineAndPosition( @@ -678,7 +678,7 @@ import java.util.concurrent.CopyOnWriteArraySet; /* positionDiscontinuity= */ true, /* positionDiscontinuityReason= */ DISCONTINUITY_REASON_SEEK, /* discontinuityWindowStartPositionUs= */ getCurrentPositionUsInternal(newPlaybackInfo), - oldMaskingWindowIndex); + oldMaskingMediaItemIndex); } @Override @@ -839,7 +839,7 @@ import java.util.concurrent.CopyOnWriteArraySet; internalPlayer, target, playbackInfo.timeline, - getCurrentWindowIndex(), + getCurrentMediaItemIndex(), clock, internalPlayer.getPlaybackLooper()); } @@ -910,7 +910,10 @@ import java.util.concurrent.CopyOnWriteArraySet; if (isPlayingAd()) { playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period); return playbackInfo.requestedContentPositionUs == C.TIME_UNSET - ? playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDefaultPositionMs() + ? playbackInfo + .timeline + .getWindow(getCurrentMediaItemIndex(), window) + .getDefaultPositionMs() : period.getPositionInWindowMs() + Util.usToMs(playbackInfo.requestedContentPositionUs); } else { return getCurrentPosition(); @@ -924,7 +927,7 @@ import java.util.concurrent.CopyOnWriteArraySet; } if (playbackInfo.loadingMediaPeriodId.windowSequenceNumber != playbackInfo.periodId.windowSequenceNumber) { - return playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); + return playbackInfo.timeline.getWindow(getCurrentMediaItemIndex(), window).getDurationMs(); } long contentBufferedPositionUs = playbackInfo.bufferedPositionUs; if (playbackInfo.loadingMediaPeriodId.isAd()) { @@ -1218,7 +1221,7 @@ import java.util.concurrent.CopyOnWriteArraySet; boolean positionDiscontinuity, @DiscontinuityReason int positionDiscontinuityReason, long discontinuityWindowStartPositionUs, - int oldMaskingWindowIndex) { + int oldMaskingMediaItemIndex) { // Assign playback info immediately such that all getters return the right values, but keep // snapshot of previous and new state so that listener invocations are triggered correctly. @@ -1267,7 +1270,7 @@ import java.util.concurrent.CopyOnWriteArraySet; if (positionDiscontinuity) { PositionInfo previousPositionInfo = getPreviousPositionInfo( - positionDiscontinuityReason, previousPlaybackInfo, oldMaskingWindowIndex); + positionDiscontinuityReason, previousPlaybackInfo, oldMaskingMediaItemIndex); PositionInfo positionInfo = getPositionInfo(discontinuityWindowStartPositionUs); listeners.queueEvent( Player.EVENT_POSITION_DISCONTINUITY, @@ -1378,19 +1381,19 @@ import java.util.concurrent.CopyOnWriteArraySet; private PositionInfo getPreviousPositionInfo( @DiscontinuityReason int positionDiscontinuityReason, PlaybackInfo oldPlaybackInfo, - int oldMaskingWindowIndex) { + int oldMaskingMediaItemIndex) { @Nullable Object oldWindowUid = null; @Nullable Object oldPeriodUid = null; - int oldWindowIndex = oldMaskingWindowIndex; + int oldMediaItemIndex = oldMaskingMediaItemIndex; int oldPeriodIndex = C.INDEX_UNSET; @Nullable MediaItem oldMediaItem = null; Timeline.Period oldPeriod = new Timeline.Period(); if (!oldPlaybackInfo.timeline.isEmpty()) { oldPeriodUid = oldPlaybackInfo.periodId.periodUid; oldPlaybackInfo.timeline.getPeriodByUid(oldPeriodUid, oldPeriod); - oldWindowIndex = oldPeriod.windowIndex; + oldMediaItemIndex = oldPeriod.windowIndex; oldPeriodIndex = oldPlaybackInfo.timeline.getIndexOfPeriod(oldPeriodUid); - oldWindowUid = oldPlaybackInfo.timeline.getWindow(oldWindowIndex, window).uid; + oldWindowUid = oldPlaybackInfo.timeline.getWindow(oldMediaItemIndex, window).uid; oldMediaItem = window.mediaItem; } long oldPositionUs; @@ -1421,7 +1424,7 @@ import java.util.concurrent.CopyOnWriteArraySet; } return new PositionInfo( oldWindowUid, - oldWindowIndex, + oldMediaItemIndex, oldMediaItem, oldPeriodUid, oldPeriodIndex, @@ -1434,20 +1437,20 @@ import java.util.concurrent.CopyOnWriteArraySet; private PositionInfo getPositionInfo(long discontinuityWindowStartPositionUs) { @Nullable Object newWindowUid = null; @Nullable Object newPeriodUid = null; - int newWindowIndex = getCurrentWindowIndex(); + int newMediaItemIndex = getCurrentMediaItemIndex(); int newPeriodIndex = C.INDEX_UNSET; @Nullable MediaItem newMediaItem = null; if (!playbackInfo.timeline.isEmpty()) { newPeriodUid = playbackInfo.periodId.periodUid; playbackInfo.timeline.getPeriodByUid(newPeriodUid, period); newPeriodIndex = playbackInfo.timeline.getIndexOfPeriod(newPeriodUid); - newWindowUid = playbackInfo.timeline.getWindow(newWindowIndex, window).uid; + newWindowUid = playbackInfo.timeline.getWindow(newMediaItemIndex, window).uid; newMediaItem = window.mediaItem; } long positionMs = Util.usToMs(discontinuityWindowStartPositionUs); return new PositionInfo( newWindowUid, - newWindowIndex, + newMediaItemIndex, newMediaItem, newPeriodUid, newPeriodIndex, @@ -1601,7 +1604,7 @@ import java.util.concurrent.CopyOnWriteArraySet; private PlaybackInfo removeMediaItemsInternal(int fromIndex, int toIndex) { Assertions.checkArgument( fromIndex >= 0 && toIndex >= fromIndex && toIndex <= mediaSourceHolderSnapshots.size()); - int currentWindowIndex = getCurrentWindowIndex(); + int currentIndex = getCurrentMediaItemIndex(); Timeline oldTimeline = getCurrentTimeline(); int currentMediaSourceCount = mediaSourceHolderSnapshots.size(); pendingOperationAcks++; @@ -1618,7 +1621,7 @@ import java.util.concurrent.CopyOnWriteArraySet; && newPlaybackInfo.playbackState != STATE_ENDED && fromIndex < toIndex && toIndex == currentMediaSourceCount - && currentWindowIndex >= newPlaybackInfo.timeline.getWindowCount(); + && currentIndex >= newPlaybackInfo.timeline.getWindowCount(); if (transitionsToEnded) { newPlaybackInfo = newPlaybackInfo.copyWithPlaybackState(STATE_ENDED); } @@ -1753,11 +1756,11 @@ import java.util.concurrent.CopyOnWriteArraySet; isCleared ? C.INDEX_UNSET : getCurrentWindowIndexInternal(), isCleared ? C.TIME_UNSET : currentPositionMs); } - int currentWindowIndex = getCurrentWindowIndex(); + int currentMediaItemIndex = getCurrentMediaItemIndex(); @Nullable Pair oldPeriodPosition = oldTimeline.getPeriodPosition( - window, period, currentWindowIndex, Util.msToUs(currentPositionMs)); + window, period, currentMediaItemIndex, Util.msToUs(currentPositionMs)); Object periodUid = castNonNull(oldPeriodPosition).first; if (newTimeline.getIndexOfPeriod(periodUid) != C.INDEX_UNSET) { // The old period position is still available in the new timeline. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 9fadb56a79..d6f1e1f73a 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -2718,7 +2718,7 @@ import java.util.concurrent.atomic.AtomicBoolean; newTimeline, new SeekPosition( pendingMessageInfo.message.getTimeline(), - pendingMessageInfo.message.getWindowIndex(), + pendingMessageInfo.message.getMediaItemIndex(), requestPositionUs), /* trySubsequentPeriods= */ false, repeatMode, diff --git a/library/core/src/main/java/com/google/android/exoplayer2/PlayerMessage.java b/library/core/src/main/java/com/google/android/exoplayer2/PlayerMessage.java index 0d591ee9f6..cc7e749fa0 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/PlayerMessage.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/PlayerMessage.java @@ -63,7 +63,7 @@ public final class PlayerMessage { private int type; @Nullable private Object payload; private Looper looper; - private int windowIndex; + private int mediaItemIndex; private long positionMs; private boolean deleteAfterDelivery; private boolean isSent; @@ -78,8 +78,8 @@ public final class PlayerMessage { * @param target The {@link Target} the message is sent to. * @param timeline The timeline used when setting the position with {@link #setPosition(long)}. If * set to {@link Timeline#EMPTY}, any position can be specified. - * @param defaultWindowIndex The default window index in the {@code timeline} when no other window - * index is specified. + * @param defaultMediaItemIndex The default media item index in the {@code timeline} when no other + * media item index is specified. * @param clock The {@link Clock}. * @param defaultLooper The default {@link Looper} to send the message on when no other looper is * specified. @@ -88,7 +88,7 @@ public final class PlayerMessage { Sender sender, Target target, Timeline timeline, - int defaultWindowIndex, + int defaultMediaItemIndex, Clock clock, Looper defaultLooper) { this.sender = sender; @@ -96,7 +96,7 @@ public final class PlayerMessage { this.timeline = timeline; this.looper = defaultLooper; this.clock = clock; - this.windowIndex = defaultWindowIndex; + this.mediaItemIndex = defaultMediaItemIndex; this.positionMs = C.TIME_UNSET; this.deleteAfterDelivery = true; } @@ -173,21 +173,21 @@ public final class PlayerMessage { } /** - * Returns position in window at {@link #getWindowIndex()} at which the message will be delivered, - * in milliseconds. If {@link C#TIME_UNSET}, the message will be delivered immediately. If {@link - * C#TIME_END_OF_SOURCE}, the message will be delivered at the end of the window at {@link - * #getWindowIndex()}. + * Returns position in the media item at {@link #getMediaItemIndex()} at which the message will be + * delivered, in milliseconds. If {@link C#TIME_UNSET}, the message will be delivered immediately. + * If {@link C#TIME_END_OF_SOURCE}, the message will be delivered at the end of the media item at + * {@link #getMediaItemIndex()}. */ public long getPositionMs() { return positionMs; } /** - * Sets a position in the current window at which the message will be delivered. + * Sets a position in the current media item at which the message will be delivered. * - * @param positionMs The position in the current window at which the message will be sent, in + * @param positionMs The position in the current media item at which the message will be sent, in * milliseconds, or {@link C#TIME_END_OF_SOURCE} to deliver the message at the end of the - * current window. + * current media item. * @return This message. * @throws IllegalStateException If {@link #send()} has already been called. */ @@ -198,31 +198,32 @@ public final class PlayerMessage { } /** - * Sets a position in a window at which the message will be delivered. + * Sets a position in a media item at which the message will be delivered. * - * @param windowIndex The index of the window at which the message will be sent. - * @param positionMs The position in the window with index {@code windowIndex} at which the + * @param mediaItemIndex The index of the media item at which the message will be sent. + * @param positionMs The position in the media item with index {@code mediaItemIndex} at which the * message will be sent, in milliseconds, or {@link C#TIME_END_OF_SOURCE} to deliver the - * message at the end of the window with index {@code windowIndex}. + * message at the end of the media item with index {@code mediaItemIndex}. * @return This message. * @throws IllegalSeekPositionException If the timeline returned by {@link #getTimeline()} is not - * empty and the provided window index is not within the bounds of the timeline. + * empty and the provided media item index is not within the bounds of the timeline. * @throws IllegalStateException If {@link #send()} has already been called. */ - public PlayerMessage setPosition(int windowIndex, long positionMs) { + public PlayerMessage setPosition(int mediaItemIndex, long positionMs) { Assertions.checkState(!isSent); Assertions.checkArgument(positionMs != C.TIME_UNSET); - if (windowIndex < 0 || (!timeline.isEmpty() && windowIndex >= timeline.getWindowCount())) { - throw new IllegalSeekPositionException(timeline, windowIndex, positionMs); + if (mediaItemIndex < 0 + || (!timeline.isEmpty() && mediaItemIndex >= timeline.getWindowCount())) { + throw new IllegalSeekPositionException(timeline, mediaItemIndex, positionMs); } - this.windowIndex = windowIndex; + this.mediaItemIndex = mediaItemIndex; this.positionMs = positionMs; return this; } - /** Returns window index at which the message will be delivered. */ - public int getWindowIndex() { - return windowIndex; + /** Returns media item index at which the message will be delivered. */ + public int getMediaItemIndex() { + return mediaItemIndex; } /** 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 3c6607611e..83067a500c 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 @@ -1110,9 +1110,9 @@ public class SimpleExoPlayer extends BasePlayer @Override public void setMediaSources( - List mediaSources, int startWindowIndex, long startPositionMs) { + List mediaSources, int startMediaItemIndex, long startPositionMs) { verifyApplicationThread(); - player.setMediaSources(mediaSources, startWindowIndex, startPositionMs); + player.setMediaSources(mediaSources, startMediaItemIndex, startPositionMs); } @Override @@ -1419,7 +1419,7 @@ public class SimpleExoPlayer extends BasePlayer @Override public int getCurrentMediaItemIndex() { verifyApplicationThread(); - return player.getCurrentWindowIndex(); + return player.getCurrentMediaItemIndex(); } @Override 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 ae22609e29..63e87a5539 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 @@ -914,7 +914,7 @@ public class AnalyticsCollector long eventPositionMs; boolean isInCurrentWindow = timeline.equals(player.getCurrentTimeline()) - && windowIndex == player.getCurrentWindowIndex(); + && windowIndex == player.getCurrentMediaItemIndex(); if (mediaPeriodId != null && mediaPeriodId.isAd()) { boolean isCurrentAd = isInCurrentWindow @@ -939,7 +939,7 @@ public class AnalyticsCollector mediaPeriodId, eventPositionMs, player.getCurrentTimeline(), - player.getCurrentWindowIndex(), + player.getCurrentMediaItemIndex(), currentMediaPeriodId, player.getCurrentPosition(), player.getTotalBufferedDuration()); @@ -962,7 +962,7 @@ public class AnalyticsCollector ? null : mediaPeriodQueueTracker.getMediaPeriodIdTimeline(mediaPeriodId); if (mediaPeriodId == null || knownTimeline == null) { - int windowIndex = player.getCurrentWindowIndex(); + int windowIndex = player.getCurrentMediaItemIndex(); Timeline timeline = player.getCurrentTimeline(); boolean windowIsInTimeline = windowIndex < timeline.getWindowCount(); return generateEventTime( 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 9887f397ea..df73a1f7f4 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 @@ -382,7 +382,7 @@ public interface AnalyticsListener { /** * The current window index in {@link #currentTimeline} at the time of the event, or the * prospective window index if the timeline is not yet known and empty (equivalent to {@link - * Player#getCurrentWindowIndex()}). + * Player#getCurrentMediaItemIndex()}). */ public final int currentWindowIndex; @@ -419,7 +419,7 @@ public interface AnalyticsListener { * {@link Player#getCurrentTimeline()}). * @param currentWindowIndex The current window index in {@code currentTimeline} at the time of * the event, or the prospective window index if the timeline is not yet known and empty - * (equivalent to {@link Player#getCurrentWindowIndex()}). + * (equivalent to {@link Player#getCurrentMediaItemIndex()}). * @param currentMediaPeriodId {@link MediaPeriodId Media period identifier} for the currently * playing media period at the time of the event, or {@code null} if no current media period * identifier is available. @@ -1204,9 +1204,9 @@ public interface AnalyticsListener { * {@link Player#seekTo(long)} after a {@link * AnalyticsListener#onMediaItemTransition(EventTime, MediaItem, int)}). *
  • They intend to use multiple state values together or in combination with {@link Player} - * getter methods. For example using {@link Player#getCurrentWindowIndex()} with the {@code - * timeline} provided in {@link #onTimelineChanged(EventTime, int)} is only safe from within - * this method. + * getter methods. For example using {@link Player#getCurrentMediaItemIndex()} with the + * {@code timeline} provided in {@link #onTimelineChanged(EventTime, int)} is only safe from + * within this method. *
  • They are interested in events that logically happened together (e.g {@link * #onPlaybackStateChanged(EventTime, int)} to {@link Player#STATE_BUFFERING} because of * {@link #onMediaItemTransition(EventTime, MediaItem, int)}). diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/DebugTextViewHelper.java b/library/core/src/main/java/com/google/android/exoplayer2/util/DebugTextViewHelper.java index 5eeaa060bc..77fb5c048e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/DebugTextViewHelper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/DebugTextViewHelper.java @@ -138,8 +138,8 @@ public class DebugTextViewHelper implements Player.Listener, Runnable { break; } return String.format( - "playWhenReady:%s playbackState:%s window:%s", - player.getPlayWhenReady(), playbackStateString, player.getCurrentWindowIndex()); + "playWhenReady:%s playbackState:%s item:%s", + player.getPlayWhenReady(), playbackStateString, player.getCurrentMediaItemIndex()); } /** Returns a string containing video debugging information. */ 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 64044b2a3f..886d3c8ed9 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 @@ -48,7 +48,7 @@ import static com.google.android.exoplayer2.Player.COMMAND_STOP; import static com.google.android.exoplayer2.Player.STATE_ENDED; import static com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil; import static com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilPosition; -import static com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfWindow; +import static com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem; import static com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled; import static com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPlaybackState; import static com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPositionDiscontinuity; @@ -381,7 +381,7 @@ public final class ExoPlayerTest { player.play(); runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION); player.setForegroundMode(/* foregroundMode= */ true); - // Only the video renderer that is disabled in the second window has been reset. + // Only the video renderer that is disabled in the second media item has been reset. assertThat(audioRenderer.resetCount).isEqualTo(0); assertThat(videoRenderer.resetCount).isEqualTo(1); @@ -460,7 +460,7 @@ public final class ExoPlayerTest { // Disable text renderer by selecting a language that is not available. player.setTrackSelectionParameters( player.getTrackSelectionParameters().buildUpon().setPreferredTextLanguage("de").build()); - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 1000); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 1000); runUntilPlaybackState(player, Player.STATE_READY); // Expect formerly enabled renderers to be reset after seek. assertThat(textRenderer.resetCount).isEqualTo(1); @@ -647,21 +647,21 @@ public final class ExoPlayerTest { player.setMediaSource(new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT)); player.prepare(); runUntilTimelineChanged(player); - playUntilStartOfWindow(player, /* windowIndex= */ 1); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 1); player.setRepeatMode(Player.REPEAT_MODE_ONE); - playUntilStartOfWindow(player, /* windowIndex= */ 1); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 1); player.setRepeatMode(Player.REPEAT_MODE_OFF); - playUntilStartOfWindow(player, /* windowIndex= */ 2); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 2); player.setRepeatMode(Player.REPEAT_MODE_ONE); - playUntilStartOfWindow(player, /* windowIndex= */ 2); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 2); player.setRepeatMode(Player.REPEAT_MODE_ALL); - playUntilStartOfWindow(player, /* windowIndex= */ 0); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 0); player.setRepeatMode(Player.REPEAT_MODE_ONE); - playUntilStartOfWindow(player, /* windowIndex= */ 0); - playUntilStartOfWindow(player, /* windowIndex= */ 0); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 0); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 0); player.setRepeatMode(Player.REPEAT_MODE_OFF); - playUntilStartOfWindow(player, /* windowIndex= */ 1); - playUntilStartOfWindow(player, /* windowIndex= */ 2); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 1); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 2); player.play(); runUntilPlaybackState(player, Player.STATE_ENDED); @@ -694,9 +694,9 @@ public final class ExoPlayerTest { .pause() .waitForPlaybackState(Player.STATE_READY) .setRepeatMode(Player.REPEAT_MODE_ALL) - .playUntilStartOfWindow(/* windowIndex= */ 1) + .playUntilStartOfMediaItem(/* mediaItemIndex= */ 1) .setShuffleModeEnabled(true) - .playUntilStartOfWindow(/* windowIndex= */ 1) + .playUntilStartOfMediaItem(/* mediaItemIndex= */ 1) .setShuffleModeEnabled(false) .setRepeatMode(Player.REPEAT_MODE_OFF) .play() @@ -806,7 +806,7 @@ public final class ExoPlayerTest { @Override public void run(ExoPlayer player) { try { - player.seekTo(/* windowIndex= */ 100, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 100, /* positionMs= */ 0); } catch (IllegalSeekPositionException e) { exception[0] = e; } @@ -1281,7 +1281,7 @@ public final class ExoPlayerTest { .play() .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 0, /* positionMs= */ 2000) + .initialSeek(/* mediaItemIndex= */ 0, /* positionMs= */ 2000) .setMediaSources(mediaSource) .setActionSchedule(actionSchedule) .build() @@ -1293,7 +1293,7 @@ public final class ExoPlayerTest { @Test public void stop_withoutReset_doesNotResetPosition_correctMasking() throws Exception { - int[] currentWindowIndex = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + int[] currentMediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; long[] currentPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; long[] bufferedPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; long[] totalBufferedDuration = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; @@ -1302,18 +1302,18 @@ public final class ExoPlayerTest { ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .pause() - .seek(/* windowIndex= */ 1, /* positionMs= */ 1000) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ 1000) .waitForPlaybackState(Player.STATE_READY) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndex[0] = player.getCurrentWindowIndex(); + currentMediaItemIndex[0] = player.getCurrentMediaItemIndex(); currentPosition[0] = player.getCurrentPosition(); bufferedPosition[0] = player.getBufferedPosition(); totalBufferedDuration[0] = player.getTotalBufferedDuration(); player.stop(/* reset= */ false); - currentWindowIndex[1] = player.getCurrentWindowIndex(); + currentMediaItemIndex[1] = player.getCurrentMediaItemIndex(); currentPosition[1] = player.getCurrentPosition(); bufferedPosition[1] = player.getBufferedPosition(); totalBufferedDuration[1] = player.getTotalBufferedDuration(); @@ -1324,7 +1324,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndex[2] = player.getCurrentWindowIndex(); + currentMediaItemIndex[2] = player.getCurrentMediaItemIndex(); currentPosition[2] = player.getCurrentPosition(); bufferedPosition[2] = player.getBufferedPosition(); totalBufferedDuration[2] = player.getTotalBufferedDuration(); @@ -1345,17 +1345,17 @@ public final class ExoPlayerTest { Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE); testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_SEEK); - assertThat(currentWindowIndex[0]).isEqualTo(1); + assertThat(currentMediaItemIndex[0]).isEqualTo(1); assertThat(currentPosition[0]).isEqualTo(1000); assertThat(bufferedPosition[0]).isEqualTo(10000); assertThat(totalBufferedDuration[0]).isEqualTo(9000); - assertThat(currentWindowIndex[1]).isEqualTo(1); + assertThat(currentMediaItemIndex[1]).isEqualTo(1); assertThat(currentPosition[1]).isEqualTo(1000); assertThat(bufferedPosition[1]).isEqualTo(1000); assertThat(totalBufferedDuration[1]).isEqualTo(0); - assertThat(currentWindowIndex[2]).isEqualTo(1); + assertThat(currentMediaItemIndex[2]).isEqualTo(1); assertThat(currentPosition[2]).isEqualTo(1000); assertThat(bufferedPosition[2]).isEqualTo(1000); assertThat(totalBufferedDuration[2]).isEqualTo(0); @@ -1385,7 +1385,7 @@ public final class ExoPlayerTest { @Test public void stop_withReset_doesResetPosition_correctMasking() throws Exception { - int[] currentWindowIndex = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + int[] currentMediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; long[] currentPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; long[] bufferedPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; long[] totalBufferedDuration = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; @@ -1394,18 +1394,18 @@ public final class ExoPlayerTest { ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .pause() - .seek(/* windowIndex= */ 1, /* positionMs= */ 1000) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ 1000) .waitForPlaybackState(Player.STATE_READY) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndex[0] = player.getCurrentWindowIndex(); + currentMediaItemIndex[0] = player.getCurrentMediaItemIndex(); currentPosition[0] = player.getCurrentPosition(); bufferedPosition[0] = player.getBufferedPosition(); totalBufferedDuration[0] = player.getTotalBufferedDuration(); player.stop(/* reset= */ true); - currentWindowIndex[1] = player.getCurrentWindowIndex(); + currentMediaItemIndex[1] = player.getCurrentMediaItemIndex(); currentPosition[1] = player.getCurrentPosition(); bufferedPosition[1] = player.getBufferedPosition(); totalBufferedDuration[1] = player.getTotalBufferedDuration(); @@ -1416,7 +1416,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndex[2] = player.getCurrentWindowIndex(); + currentMediaItemIndex[2] = player.getCurrentMediaItemIndex(); currentPosition[2] = player.getCurrentPosition(); bufferedPosition[2] = player.getBufferedPosition(); totalBufferedDuration[2] = player.getTotalBufferedDuration(); @@ -1439,17 +1439,17 @@ public final class ExoPlayerTest { testRunner.assertPositionDiscontinuityReasonsEqual( Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_REMOVE); - assertThat(currentWindowIndex[0]).isEqualTo(1); + assertThat(currentMediaItemIndex[0]).isEqualTo(1); assertThat(currentPosition[0]).isGreaterThan(0); assertThat(bufferedPosition[0]).isEqualTo(10000); assertThat(totalBufferedDuration[0]).isEqualTo(10000 - currentPosition[0]); - assertThat(currentWindowIndex[1]).isEqualTo(0); + assertThat(currentMediaItemIndex[1]).isEqualTo(0); assertThat(currentPosition[1]).isEqualTo(0); assertThat(bufferedPosition[1]).isEqualTo(0); assertThat(totalBufferedDuration[1]).isEqualTo(0); - assertThat(currentWindowIndex[2]).isEqualTo(0); + assertThat(currentMediaItemIndex[2]).isEqualTo(0); assertThat(currentPosition[2]).isEqualTo(0); assertThat(bufferedPosition[2]).isEqualTo(0); assertThat(totalBufferedDuration[2]).isEqualTo(0); @@ -1479,7 +1479,7 @@ public final class ExoPlayerTest { @Test public void release_correctMasking() throws Exception { - int[] currentWindowIndex = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + int[] currentMediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; long[] currentPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; long[] bufferedPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; long[] totalBufferedDuration = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; @@ -1488,18 +1488,18 @@ public final class ExoPlayerTest { ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .pause() - .seek(/* windowIndex= */ 1, /* positionMs= */ 1000) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ 1000) .waitForPlaybackState(Player.STATE_READY) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndex[0] = player.getCurrentWindowIndex(); + currentMediaItemIndex[0] = player.getCurrentMediaItemIndex(); currentPosition[0] = player.getCurrentPosition(); bufferedPosition[0] = player.getBufferedPosition(); totalBufferedDuration[0] = player.getTotalBufferedDuration(); player.release(); - currentWindowIndex[1] = player.getCurrentWindowIndex(); + currentMediaItemIndex[1] = player.getCurrentMediaItemIndex(); currentPosition[1] = player.getCurrentPosition(); bufferedPosition[1] = player.getBufferedPosition(); totalBufferedDuration[1] = player.getTotalBufferedDuration(); @@ -1510,7 +1510,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndex[2] = player.getCurrentWindowIndex(); + currentMediaItemIndex[2] = player.getCurrentMediaItemIndex(); currentPosition[2] = player.getCurrentPosition(); bufferedPosition[2] = player.getBufferedPosition(); totalBufferedDuration[2] = player.getTotalBufferedDuration(); @@ -1525,17 +1525,17 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS); - assertThat(currentWindowIndex[0]).isEqualTo(1); + assertThat(currentMediaItemIndex[0]).isEqualTo(1); assertThat(currentPosition[0]).isGreaterThan(0); assertThat(bufferedPosition[0]).isEqualTo(10000); assertThat(totalBufferedDuration[0]).isEqualTo(10000 - currentPosition[0]); - assertThat(currentWindowIndex[1]).isEqualTo(1); + assertThat(currentMediaItemIndex[1]).isEqualTo(1); assertThat(currentPosition[1]).isEqualTo(currentPosition[0]); assertThat(bufferedPosition[1]).isEqualTo(1000); assertThat(totalBufferedDuration[1]).isEqualTo(0); - assertThat(currentWindowIndex[2]).isEqualTo(1); + assertThat(currentMediaItemIndex[2]).isEqualTo(1); assertThat(currentPosition[2]).isEqualTo(currentPosition[0]); assertThat(bufferedPosition[2]).isEqualTo(1000); assertThat(totalBufferedDuration[2]).isEqualTo(0); @@ -1547,21 +1547,21 @@ public final class ExoPlayerTest { Timeline secondTimeline = new FakeTimeline(/* windowCount= */ 2); MediaSource secondSource = new FakeMediaSource(secondTimeline, ExoPlayerTestRunner.VIDEO_FORMAT); - AtomicInteger windowIndexAfterStop = new AtomicInteger(); + AtomicInteger mediaItemIndexAfterStop = new AtomicInteger(); AtomicLong positionAfterStop = new AtomicLong(); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlaybackState(Player.STATE_READY) .stop(/* reset= */ true) .waitForPlaybackState(Player.STATE_IDLE) - .seek(/* windowIndex= */ 1, /* positionMs= */ 1000) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ 1000) .setMediaSources(secondSource) .prepare() .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndexAfterStop.set(player.getCurrentWindowIndex()); + mediaItemIndexAfterStop.set(player.getCurrentMediaItemIndex()); positionAfterStop.set(player.getCurrentPosition()); } }) @@ -1594,7 +1594,7 @@ public final class ExoPlayerTest { Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, // stop(true) Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE); - assertThat(windowIndexAfterStop.get()).isEqualTo(1); + assertThat(mediaItemIndexAfterStop.get()).isEqualTo(1); assertThat(positionAfterStop.get()).isAtLeast(1000L); testRunner.assertPlayedPeriodIndices(0, 1); } @@ -1621,8 +1621,8 @@ public final class ExoPlayerTest { new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_READY) - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 2000) - .setMediaSources(/* windowIndex= */ 0, /* positionMs= */ 2000, secondSource) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 2000) + .setMediaSources(/* mediaItemIndex= */ 0, /* positionMs= */ 2000, secondSource) .waitForTimelineChanged( secondTimeline, /* expectedReason */ Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) .executeRunnable( @@ -1675,7 +1675,7 @@ public final class ExoPlayerTest { new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_READY) - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 2000) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 2000) .setMediaSources(/* resetPosition= */ true, secondSource) .waitForTimelineChanged( secondTimeline, /* expectedReason */ Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) @@ -1732,7 +1732,7 @@ public final class ExoPlayerTest { new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_READY) - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 2000) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 2000) .setMediaSources(secondSource) .waitForTimelineChanged( secondTimeline, /* expectedReason */ Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) @@ -1892,7 +1892,7 @@ public final class ExoPlayerTest { throws Exception { ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(/* isAtomic= */ false, new FakeShuffleOrder(0)); - AtomicInteger windowIndexAfterAddingSources = new AtomicInteger(); + AtomicInteger mediaItemIndexAfterAddingSources = new AtomicInteger(); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .setShuffleModeEnabled(true) @@ -1909,7 +1909,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndexAfterAddingSources.set(player.getCurrentWindowIndex()); + mediaItemIndexAfterAddingSources.set(player.getCurrentMediaItemIndex()); } }) .build(); @@ -1920,20 +1920,20 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertThat(windowIndexAfterAddingSources.get()).isEqualTo(1); + assertThat(mediaItemIndexAfterAddingSources.get()).isEqualTo(1); } @Test public void playbackErrorAndReprepareDoesNotResetPosition() throws Exception { final Timeline timeline = new FakeTimeline(/* windowCount= */ 2); final long[] positionHolder = new long[3]; - final int[] windowIndexHolder = new int[3]; + final int[] mediaItemIndexHolder = new int[3]; final FakeMediaSource firstMediaSource = new FakeMediaSource(timeline); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_READY) - .playUntilPosition(/* windowIndex= */ 1, /* positionMs= */ 500) + .playUntilPosition(/* mediaItemIndex= */ 1, /* positionMs= */ 500) .throwPlaybackException( ExoPlaybackException.createForSource( new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)) @@ -1944,7 +1944,7 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Position while in error state positionHolder[0] = player.getCurrentPosition(); - windowIndexHolder[0] = player.getCurrentWindowIndex(); + mediaItemIndexHolder[0] = player.getCurrentMediaItemIndex(); } }) .prepare() @@ -1954,7 +1954,7 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Position while repreparing. positionHolder[1] = player.getCurrentPosition(); - windowIndexHolder[1] = player.getCurrentWindowIndex(); + mediaItemIndexHolder[1] = player.getCurrentMediaItemIndex(); } }) .waitForPlaybackState(Player.STATE_READY) @@ -1964,7 +1964,7 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Position after repreparation finished. positionHolder[2] = player.getCurrentPosition(); - windowIndexHolder[2] = player.getCurrentWindowIndex(); + mediaItemIndexHolder[2] = player.getCurrentMediaItemIndex(); } }) .play() @@ -1983,22 +1983,22 @@ public final class ExoPlayerTest { assertThat(positionHolder[0]).isAtLeast(500L); assertThat(positionHolder[1]).isEqualTo(positionHolder[0]); assertThat(positionHolder[2]).isEqualTo(positionHolder[0]); - assertThat(windowIndexHolder[0]).isEqualTo(1); - assertThat(windowIndexHolder[1]).isEqualTo(1); - assertThat(windowIndexHolder[2]).isEqualTo(1); + assertThat(mediaItemIndexHolder[0]).isEqualTo(1); + assertThat(mediaItemIndexHolder[1]).isEqualTo(1); + assertThat(mediaItemIndexHolder[2]).isEqualTo(1); } @Test public void seekAfterPlaybackError() throws Exception { final Timeline timeline = new FakeTimeline(/* windowCount= */ 2); final long[] positionHolder = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; - final int[] windowIndexHolder = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndexHolder = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; final FakeMediaSource firstMediaSource = new FakeMediaSource(timeline); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_READY) - .playUntilPosition(/* windowIndex= */ 1, /* positionMs= */ 500) + .playUntilPosition(/* mediaItemIndex= */ 1, /* positionMs= */ 500) .throwPlaybackException( ExoPlaybackException.createForSource( new IOException(), PlaybackException.ERROR_CODE_IO_UNSPECIFIED)) @@ -2009,10 +2009,10 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Position while in error state positionHolder[0] = player.getCurrentPosition(); - windowIndexHolder[0] = player.getCurrentWindowIndex(); + mediaItemIndexHolder[0] = player.getCurrentMediaItemIndex(); } }) - .seek(/* windowIndex= */ 0, /* positionMs= */ C.TIME_UNSET) + .seek(/* mediaItemIndex= */ 0, /* positionMs= */ C.TIME_UNSET) .waitForPendingPlayerCommands() .executeRunnable( new PlayerRunnable() { @@ -2020,7 +2020,7 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Position while in error state positionHolder[1] = player.getCurrentPosition(); - windowIndexHolder[1] = player.getCurrentWindowIndex(); + mediaItemIndexHolder[1] = player.getCurrentMediaItemIndex(); } }) .prepare() @@ -2030,7 +2030,7 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Position after prepare. positionHolder[2] = player.getCurrentPosition(); - windowIndexHolder[2] = player.getCurrentWindowIndex(); + mediaItemIndexHolder[2] = player.getCurrentMediaItemIndex(); } }) .play() @@ -2051,9 +2051,9 @@ public final class ExoPlayerTest { assertThat(positionHolder[0]).isAtLeast(500L); assertThat(positionHolder[1]).isEqualTo(0L); assertThat(positionHolder[2]).isEqualTo(0L); - assertThat(windowIndexHolder[0]).isEqualTo(1); - assertThat(windowIndexHolder[1]).isEqualTo(0); - assertThat(windowIndexHolder[2]).isEqualTo(0); + assertThat(mediaItemIndexHolder[0]).isEqualTo(1); + assertThat(mediaItemIndexHolder[1]).isEqualTo(0); + assertThat(mediaItemIndexHolder[2]).isEqualTo(0); } @Test @@ -2216,7 +2216,7 @@ public final class ExoPlayerTest { .pause() .sendMessage( (messageType, payload) -> counter.getAndIncrement(), - /* windowIndex= */ 0, + /* mediaItemIndex= */ 0, /* positionMs= */ 2000, /* deleteAfterDelivery= */ false) .seek(/* positionMs= */ 2000) @@ -2290,23 +2290,23 @@ public final class ExoPlayerTest { long duration2Ms = timeline.getWindow(1, new Window()).getDurationMs(); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) - .sendMessage(targetStartFirstPeriod, /* windowIndex= */ 0, /* positionMs= */ 0) + .sendMessage(targetStartFirstPeriod, /* mediaItemIndex= */ 0, /* positionMs= */ 0) .sendMessage( targetEndMiddlePeriodResolved, - /* windowIndex= */ 0, + /* mediaItemIndex= */ 0, /* positionMs= */ duration1Ms - 1) .sendMessage( targetEndMiddlePeriodUnresolved, - /* windowIndex= */ 0, + /* mediaItemIndex= */ 0, /* positionMs= */ C.TIME_END_OF_SOURCE) - .sendMessage(targetStartMiddlePeriod, /* windowIndex= */ 1, /* positionMs= */ 0) + .sendMessage(targetStartMiddlePeriod, /* mediaItemIndex= */ 1, /* positionMs= */ 0) .sendMessage( targetEndLastPeriodResolved, - /* windowIndex= */ 1, + /* mediaItemIndex= */ 1, /* positionMs= */ duration2Ms - 1) .sendMessage( targetEndLastPeriodUnresolved, - /* windowIndex= */ 1, + /* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_END_OF_SOURCE) .waitForMessage(targetEndLastPeriodUnresolved) .build(); @@ -2317,19 +2317,19 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertThat(targetStartFirstPeriod.windowIndex).isEqualTo(0); + assertThat(targetStartFirstPeriod.mediaItemIndex).isEqualTo(0); assertThat(targetStartFirstPeriod.positionMs).isAtLeast(0L); - assertThat(targetEndMiddlePeriodResolved.windowIndex).isEqualTo(0); + assertThat(targetEndMiddlePeriodResolved.mediaItemIndex).isEqualTo(0); assertThat(targetEndMiddlePeriodResolved.positionMs).isAtLeast(duration1Ms - 1); - assertThat(targetEndMiddlePeriodUnresolved.windowIndex).isEqualTo(0); + assertThat(targetEndMiddlePeriodUnresolved.mediaItemIndex).isEqualTo(0); assertThat(targetEndMiddlePeriodUnresolved.positionMs).isAtLeast(duration1Ms - 1); assertThat(targetEndMiddlePeriodResolved.positionMs) .isEqualTo(targetEndMiddlePeriodUnresolved.positionMs); - assertThat(targetStartMiddlePeriod.windowIndex).isEqualTo(1); + assertThat(targetStartMiddlePeriod.mediaItemIndex).isEqualTo(1); assertThat(targetStartMiddlePeriod.positionMs).isAtLeast(0L); - assertThat(targetEndLastPeriodResolved.windowIndex).isEqualTo(1); + assertThat(targetEndLastPeriodResolved.mediaItemIndex).isEqualTo(1); assertThat(targetEndLastPeriodResolved.positionMs).isAtLeast(duration2Ms - 1); - assertThat(targetEndLastPeriodUnresolved.windowIndex).isEqualTo(1); + assertThat(targetEndLastPeriodUnresolved.mediaItemIndex).isEqualTo(1); assertThat(targetEndLastPeriodUnresolved.positionMs).isAtLeast(duration2Ms - 1); assertThat(targetEndLastPeriodResolved.positionMs) .isEqualTo(targetEndLastPeriodUnresolved.positionMs); @@ -2445,12 +2445,12 @@ public final class ExoPlayerTest { .waitForPlaybackState(Player.STATE_BUFFERING) .sendMessage( target, - /* windowIndex= */ 0, + /* mediaItemIndex= */ 0, /* positionMs= */ 50, /* deleteAfterDelivery= */ false) .setRepeatMode(Player.REPEAT_MODE_ALL) - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 1) - .playUntilStartOfWindow(/* windowIndex= */ 0) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 1) + .playUntilStartOfMediaItem(/* mediaItemIndex= */ 0) .setRepeatMode(Player.REPEAT_MODE_OFF) .play() .build(); @@ -2464,7 +2464,7 @@ public final class ExoPlayerTest { } @Test - public void sendMessagesMoveCurrentWindowIndex() throws Exception { + public void sendMessagesMoveCurrentMediaItemIndex() throws Exception { Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */ 1, /* id= */ 0)); final Timeline secondTimeline = @@ -2492,7 +2492,7 @@ public final class ExoPlayerTest { .start() .blockUntilEnded(TIMEOUT_MS); assertThat(target.positionMs).isAtLeast(50L); - assertThat(target.windowIndex).isEqualTo(1); + assertThat(target.mediaItemIndex).isEqualTo(1); } @Test @@ -2503,7 +2503,7 @@ public final class ExoPlayerTest { new ActionSchedule.Builder(TAG) .pause() .waitForTimelineChanged(timeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) - .sendMessage(target, /* windowIndex = */ 2, /* positionMs= */ 50) + .sendMessage(target, /* mediaItemIndex = */ 2, /* positionMs= */ 50) .play() .build(); new ExoPlayerTestRunner.Builder(context) @@ -2512,7 +2512,7 @@ public final class ExoPlayerTest { .build() .start() .blockUntilEnded(TIMEOUT_MS); - assertThat(target.windowIndex).isEqualTo(2); + assertThat(target.mediaItemIndex).isEqualTo(2); assertThat(target.positionMs).isAtLeast(50L); } @@ -2525,7 +2525,7 @@ public final class ExoPlayerTest { .pause() .waitForTimelineChanged( timeline, /* expectedReason */ Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) - .sendMessage(target, /* windowIndex = */ 2, /* positionMs= */ 50) + .sendMessage(target, /* mediaItemIndex = */ 2, /* positionMs= */ 50) .play() .build(); new ExoPlayerTestRunner.Builder(context) @@ -2534,12 +2534,12 @@ public final class ExoPlayerTest { .build() .start() .blockUntilEnded(TIMEOUT_MS); - assertThat(target.windowIndex).isEqualTo(2); + assertThat(target.mediaItemIndex).isEqualTo(2); assertThat(target.positionMs).isAtLeast(50L); } @Test - public void sendMessagesMoveWindowIndex() throws Exception { + public void sendMessagesMoveMediaItemIndex() throws Exception { Timeline timeline = new FakeTimeline( new TimelineWindowDefinition(/* periodCount= */ 1, /* id= */ 0), @@ -2556,11 +2556,11 @@ public final class ExoPlayerTest { .pause() .waitForTimelineChanged( timeline, /* expectedReason */ Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) - .sendMessage(target, /* windowIndex = */ 1, /* positionMs= */ 50) + .sendMessage(target, /* mediaItemIndex = */ 1, /* positionMs= */ 50) .executeRunnable(() -> mediaSource.setNewSourceInfo(secondTimeline)) .waitForTimelineChanged( secondTimeline, /* expectedReason */ Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) - .seek(/* windowIndex= */ 0, /* positionMs= */ 0) + .seek(/* mediaItemIndex= */ 0, /* positionMs= */ 0) .play() .build(); new ExoPlayerTestRunner.Builder(context) @@ -2570,7 +2570,7 @@ public final class ExoPlayerTest { .start() .blockUntilEnded(TIMEOUT_MS); assertThat(target.positionMs).isAtLeast(50L); - assertThat(target.windowIndex).isEqualTo(0); + assertThat(target.mediaItemIndex).isEqualTo(0); } @Test @@ -2590,11 +2590,11 @@ public final class ExoPlayerTest { new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_READY) - .sendMessage(target1, /* windowIndex = */ 0, /* positionMs= */ 50) - .sendMessage(target2, /* windowIndex = */ 1, /* positionMs= */ 50) - .sendMessage(target3, /* windowIndex = */ 2, /* positionMs= */ 50) + .sendMessage(target1, /* mediaItemIndex = */ 0, /* positionMs= */ 50) + .sendMessage(target2, /* mediaItemIndex = */ 1, /* positionMs= */ 50) + .sendMessage(target3, /* mediaItemIndex = */ 2, /* positionMs= */ 50) .setShuffleModeEnabled(true) - .seek(/* windowIndex= */ 2, /* positionMs= */ 0) + .seek(/* mediaItemIndex= */ 2, /* positionMs= */ 0) .play() .build(); new ExoPlayerTestRunner.Builder(context) @@ -2603,9 +2603,9 @@ public final class ExoPlayerTest { .build() .start() .blockUntilEnded(TIMEOUT_MS); - assertThat(target1.windowIndex).isEqualTo(0); - assertThat(target2.windowIndex).isEqualTo(1); - assertThat(target3.windowIndex).isEqualTo(2); + assertThat(target1.mediaItemIndex).isEqualTo(0); + assertThat(target2.mediaItemIndex).isEqualTo(1); + assertThat(target3.mediaItemIndex).isEqualTo(2); } @Test @@ -2625,7 +2625,7 @@ public final class ExoPlayerTest { } }) // Play a bit to ensure message arrived in internal player. - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 30) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 30) .executeRunnable(() -> message.get().cancel()) .play() .build(); @@ -2659,7 +2659,7 @@ public final class ExoPlayerTest { } }) // Play until the message has been delivered. - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 51) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 51) // Seek back, cancel the message, and play past the same position again. .seek(/* positionMs= */ 0) .executeRunnable(() -> message.get().cancel()) @@ -2681,13 +2681,13 @@ public final class ExoPlayerTest { player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource())); player .createMessage((messageType, payload) -> {}) - .setPosition(/* windowIndex= */ 0, /* positionMs= */ 0) + .setPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 0) .setDeleteAfterDelivery(false) .send(); PlayerMessage.Target secondMediaItemTarget = mock(PlayerMessage.Target.class); player .createMessage(secondMediaItemTarget) - .setPosition(/* windowIndex= */ 1, /* positionMs= */ 0) + .setPosition(/* mediaItemIndex= */ 1, /* positionMs= */ 0) .setDeleteAfterDelivery(false) .send(); @@ -2765,7 +2765,7 @@ public final class ExoPlayerTest { .waitForPlaybackState(Player.STATE_READY) // Ensure next period is pre-buffered by playing until end of first period. .playUntilPosition( - /* windowIndex= */ 0, + /* mediaItemIndex= */ 0, /* positionMs= */ Util.usToMs(TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US)) .executeRunnable(() -> mediaSource.setNewSourceInfo(timeline2)) .waitForTimelineChanged( @@ -2921,12 +2921,12 @@ public final class ExoPlayerTest { new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_READY) - .seek(/* windowIndex= */ 0, /* positionMs= */ 9999) + .seek(/* mediaItemIndex= */ 0, /* positionMs= */ 9999) // Wait after each seek until the internal player has updated its state. .waitForPendingPlayerCommands() - .seek(/* windowIndex= */ 0, /* positionMs= */ 1) + .seek(/* mediaItemIndex= */ 0, /* positionMs= */ 1) .waitForPendingPlayerCommands() - .seek(/* windowIndex= */ 0, /* positionMs= */ 9999) + .seek(/* mediaItemIndex= */ 0, /* positionMs= */ 9999) .waitForPendingPlayerCommands() .play() .build(); @@ -2988,7 +2988,7 @@ public final class ExoPlayerTest { } catch (InterruptedException e) { throw new IllegalStateException(e); } - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 1000L); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 1000L); } }) .waitForPendingPlayerCommands() @@ -3254,8 +3254,8 @@ public final class ExoPlayerTest { .setRepeatMode(Player.REPEAT_MODE_ALL) .waitForPlaybackState(Player.STATE_READY) // Play until the media repeats once. - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 1) - .playUntilStartOfWindow(/* windowIndex= */ 0) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 1) + .playUntilStartOfMediaItem(/* mediaItemIndex= */ 0) .setRepeatMode(Player.REPEAT_MODE_OFF) .play() .build(); @@ -3289,7 +3289,7 @@ public final class ExoPlayerTest { new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_READY) - .seek(/* windowIndex= */ 1, /* positionMs= */ 0) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ 0) .waitForPendingPlayerCommands() .play() .build(); @@ -3337,7 +3337,7 @@ public final class ExoPlayerTest { .pause() .waitForPlaybackState(Player.STATE_READY) // Play almost to end to ensure the current period is fully buffered. - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 90) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 90) // Enable repeat mode to trigger the creation of new media periods. .setRepeatMode(Player.REPEAT_MODE_ALL) // Remove the media source. @@ -3852,20 +3852,20 @@ public final class ExoPlayerTest { return Timeline.EMPTY; } }; - int[] currentWindowIndices = new int[1]; + int[] currentMediaItemIndices = new int[1]; long[] currentPlaybackPositions = new long[1]; long[] windowCounts = new long[1]; - int seekToWindowIndex = 1; + int seekToMediaItemIndex = 1; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) - .seek(/* windowIndex= */ 1, /* positionMs= */ 5000) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ 5000) .waitForTimelineChanged( /* expectedTimeline= */ null, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPlaybackPositions[0] = player.getCurrentPosition(); windowCounts[0] = player.getCurrentTimeline().getWindowCount(); } @@ -3882,23 +3882,23 @@ public final class ExoPlayerTest { exoPlayerTestRunner.assertTimelineChangeReasonsEqual( Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE); assertArrayEquals(new long[] {2}, windowCounts); - assertArrayEquals(new int[] {seekToWindowIndex}, currentWindowIndices); + assertArrayEquals(new int[] {seekToMediaItemIndex}, currentMediaItemIndices); assertArrayEquals(new long[] {5_000}, currentPlaybackPositions); } @SuppressWarnings("deprecation") @Test - public void seekTo_windowIndexIsReset_deprecated() throws Exception { + public void seekTo_mediaItemIndexIsReset_deprecated() throws Exception { FakeTimeline fakeTimeline = new FakeTimeline(); FakeMediaSource mediaSource = new FakeMediaSource(fakeTimeline); - final int[] windowIndex = {C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET}; final long[] positionMs = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .pause() - .seek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) - .playUntilPosition(/* windowIndex= */ 1, /* positionMs= */ 3000) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .playUntilPosition(/* mediaItemIndex= */ 1, /* positionMs= */ 3000) .executeRunnable( new PlayerRunnable() { @Override @@ -3917,7 +3917,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndex[0] = player.getCurrentWindowIndex(); + mediaItemIndex[0] = player.getCurrentMediaItemIndex(); positionMs[2] = player.getCurrentPosition(); bufferedPositions[2] = player.getBufferedPosition(); } @@ -3930,7 +3930,7 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isAtLeast(3000L); assertThat(positionMs[1]).isEqualTo(7000L); assertThat(positionMs[2]).isEqualTo(7000L); @@ -3941,17 +3941,17 @@ public final class ExoPlayerTest { } @Test - public void seekTo_windowIndexIsReset() throws Exception { + public void seekTo_mediaItemIndexIsReset() throws Exception { FakeTimeline fakeTimeline = new FakeTimeline(); FakeMediaSource mediaSource = new FakeMediaSource(fakeTimeline); - final int[] windowIndex = {C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET}; final long[] positionMs = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .pause() - .seek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) - .playUntilPosition(/* windowIndex= */ 1, /* positionMs= */ 3000) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .playUntilPosition(/* mediaItemIndex= */ 1, /* positionMs= */ 3000) .pause() .executeRunnable( new PlayerRunnable() { @@ -3970,7 +3970,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndex[0] = player.getCurrentWindowIndex(); + mediaItemIndex[0] = player.getCurrentMediaItemIndex(); positionMs[2] = player.getCurrentPosition(); bufferedPositions[2] = player.getBufferedPosition(); } @@ -3983,7 +3983,7 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isAtLeast(3000); assertThat(positionMs[1]).isEqualTo(7000); assertThat(positionMs[2]).isEqualTo(7000); @@ -3995,7 +3995,7 @@ public final class ExoPlayerTest { @Test public void seekTo_singlePeriod_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4007,19 +4007,19 @@ public final class ExoPlayerTest { player.seekTo(9000); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 9200)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isEqualTo(9000); assertThat(bufferedPositions[0]).isEqualTo(9200); assertThat(totalBufferedDuration[0]).isEqualTo(200); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(9200); assertThat(totalBufferedDuration[1]).isEqualTo(200); @@ -4027,7 +4027,7 @@ public final class ExoPlayerTest { @Test public void seekTo_singlePeriod_beyondBufferedData_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4039,19 +4039,19 @@ public final class ExoPlayerTest { player.seekTo(9200); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 9200)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isEqualTo(9200); assertThat(bufferedPositions[0]).isEqualTo(9200); assertThat(totalBufferedDuration[0]).isEqualTo(0); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(9200); assertThat(totalBufferedDuration[1]).isEqualTo(0); @@ -4059,7 +4059,7 @@ public final class ExoPlayerTest { @Test public void seekTo_backwardsSinglePeriod_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4071,14 +4071,14 @@ public final class ExoPlayerTest { player.seekTo(1000); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 9200)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isEqualTo(1000); assertThat(bufferedPositions[0]).isEqualTo(1000); assertThat(totalBufferedDuration[0]).isEqualTo(0); @@ -4086,7 +4086,7 @@ public final class ExoPlayerTest { @Test public void seekTo_backwardsMultiplePeriods_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4098,8 +4098,8 @@ public final class ExoPlayerTest { player.seekTo(0, 1000); } }, - /* pauseWindowIndex= */ 1, - windowIndex, + /* pauseMediaItemIndex= */ 1, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, @@ -4107,7 +4107,7 @@ public final class ExoPlayerTest { new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 9200)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isEqualTo(1000); assertThat(bufferedPositions[0]).isEqualTo(1000); assertThat(totalBufferedDuration[0]).isEqualTo(0); @@ -4115,7 +4115,7 @@ public final class ExoPlayerTest { @Test public void seekTo_toUnbufferedPeriod_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4127,8 +4127,8 @@ public final class ExoPlayerTest { player.seekTo(2, 1000); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, @@ -4136,12 +4136,12 @@ public final class ExoPlayerTest { new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 0)); - assertThat(windowIndex[0]).isEqualTo(2); + assertThat(mediaItemIndex[0]).isEqualTo(2); assertThat(positionMs[0]).isEqualTo(1000); assertThat(bufferedPositions[0]).isEqualTo(1000); assertThat(totalBufferedDuration[0]).isEqualTo(0); - assertThat(windowIndex[1]).isEqualTo(2); + assertThat(mediaItemIndex[1]).isEqualTo(2); assertThat(positionMs[1]).isEqualTo(1000); assertThat(bufferedPositions[1]).isEqualTo(1000); assertThat(totalBufferedDuration[1]).isEqualTo(0); @@ -4149,7 +4149,7 @@ public final class ExoPlayerTest { @Test public void seekTo_toLoadingPeriod_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4161,22 +4161,22 @@ public final class ExoPlayerTest { player.seekTo(1, 1000); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), new FakeMediaSource()); - assertThat(windowIndex[0]).isEqualTo(1); + assertThat(mediaItemIndex[0]).isEqualTo(1); assertThat(positionMs[0]).isEqualTo(1000); // TODO(b/160450903): Verify masking of buffering properties when behaviour in EPII is fully // covered. // assertThat(bufferedPositions[0]).isEqualTo(10_000); // assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(10_000); assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[1]); @@ -4185,7 +4185,7 @@ public final class ExoPlayerTest { @Test public void seekTo_toLoadingPeriod_withinPartiallyBufferedData_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4197,22 +4197,22 @@ public final class ExoPlayerTest { player.seekTo(1, 1000); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(1); + assertThat(mediaItemIndex[0]).isEqualTo(1); assertThat(positionMs[0]).isEqualTo(1000); // TODO(b/160450903): Verify masking of buffering properties when behaviour in EPII is fully // covered. // assertThat(bufferedPositions[0]).isEqualTo(1000); // assertThat(totalBufferedDuration[0]).isEqualTo(0); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(4000); assertThat(totalBufferedDuration[1]).isEqualTo(3000); @@ -4220,7 +4220,7 @@ public final class ExoPlayerTest { @Test public void seekTo_toLoadingPeriod_beyondBufferedData_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4232,20 +4232,20 @@ public final class ExoPlayerTest { player.seekTo(1, 5000); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(1); + assertThat(mediaItemIndex[0]).isEqualTo(1); assertThat(positionMs[0]).isEqualTo(5000); assertThat(bufferedPositions[0]).isEqualTo(5000); assertThat(totalBufferedDuration[0]).isEqualTo(0); - assertThat(windowIndex[1]).isEqualTo(1); + assertThat(mediaItemIndex[1]).isEqualTo(1); assertThat(positionMs[1]).isEqualTo(5000); assertThat(bufferedPositions[1]).isEqualTo(5000); assertThat(totalBufferedDuration[1]).isEqualTo(0); @@ -4253,7 +4253,7 @@ public final class ExoPlayerTest { @Test public void seekTo_toInnerFullyBufferedPeriod_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4265,8 +4265,8 @@ public final class ExoPlayerTest { player.seekTo(1, 5000); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, @@ -4274,14 +4274,14 @@ public final class ExoPlayerTest { new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(1); + assertThat(mediaItemIndex[0]).isEqualTo(1); assertThat(positionMs[0]).isEqualTo(5000); // TODO(b/160450903): Verify masking of buffering properties when behaviour in EPII is fully // covered. // assertThat(bufferedPositions[0]).isEqualTo(10_000); // assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(10_000); assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[1]); @@ -4289,7 +4289,7 @@ public final class ExoPlayerTest { @Test public void addMediaSource_withinBufferedPeriods_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4302,20 +4302,20 @@ public final class ExoPlayerTest { /* index= */ 1, createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 0)); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isAtLeast(8000); assertThat(bufferedPositions[0]).isEqualTo(10_000); assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(10_000); assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[1]); @@ -4323,7 +4323,7 @@ public final class ExoPlayerTest { @Test public void moveMediaItem_behindLoadingPeriod_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4335,8 +4335,8 @@ public final class ExoPlayerTest { player.moveMediaItem(/* currentIndex= */ 1, /* newIndex= */ 2); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, @@ -4344,12 +4344,12 @@ public final class ExoPlayerTest { new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isAtLeast(8000); assertThat(bufferedPositions[0]).isEqualTo(10_000); assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(10_000); assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[1]); @@ -4357,7 +4357,7 @@ public final class ExoPlayerTest { @Test public void moveMediaItem_undloadedBehindPlaying_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4369,8 +4369,8 @@ public final class ExoPlayerTest { player.moveMediaItem(/* currentIndex= */ 3, /* newIndex= */ 1); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, @@ -4379,12 +4379,12 @@ public final class ExoPlayerTest { createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 0)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isAtLeast(8000); assertThat(bufferedPositions[0]).isEqualTo(10_000); assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(10000); assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[1]); @@ -4392,7 +4392,7 @@ public final class ExoPlayerTest { @Test public void removeMediaItem_removePlayingWindow_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4404,22 +4404,22 @@ public final class ExoPlayerTest { player.removeMediaItem(/* index= */ 0); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isEqualTo(0); // TODO(b/160450903): Verify masking of buffering properties when behaviour in EPII is fully // covered. // assertThat(bufferedPositions[0]).isEqualTo(4000); // assertThat(totalBufferedDuration[0]).isEqualTo(4000); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(4000); assertThat(totalBufferedDuration[1]).isEqualTo(4000); @@ -4427,7 +4427,7 @@ public final class ExoPlayerTest { @Test public void removeMediaItem_removeLoadingWindow_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4439,8 +4439,8 @@ public final class ExoPlayerTest { player.removeMediaItem(/* index= */ 2); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, @@ -4448,12 +4448,12 @@ public final class ExoPlayerTest { new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isAtLeast(8000); assertThat(bufferedPositions[0]).isEqualTo(10_000); assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(10_000); assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[1]); @@ -4462,7 +4462,7 @@ public final class ExoPlayerTest { @Test public void removeMediaItem_removeInnerFullyBufferedWindow_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4474,8 +4474,8 @@ public final class ExoPlayerTest { player.removeMediaItem(/* index= */ 1); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, @@ -4483,12 +4483,12 @@ public final class ExoPlayerTest { new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isEqualTo(8000); assertThat(bufferedPositions[0]).isEqualTo(10_000); assertThat(totalBufferedDuration[0]).isEqualTo(10_000 - positionMs[0]); - assertThat(windowIndex[1]).isEqualTo(0); + assertThat(mediaItemIndex[1]).isEqualTo(0); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(10_000); assertThat(totalBufferedDuration[1]).isEqualTo(10_000 - positionMs[0]); @@ -4496,7 +4496,7 @@ public final class ExoPlayerTest { @Test public void clearMediaItems_correctMaskingPosition() throws Exception { - final int[] windowIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] mediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] positionMs = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] bufferedPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] totalBufferedDuration = {C.INDEX_UNSET, C.INDEX_UNSET}; @@ -4508,8 +4508,8 @@ public final class ExoPlayerTest { player.clearMediaItems(); } }, - /* pauseWindowIndex= */ 0, - windowIndex, + /* pauseMediaItemIndex= */ 0, + mediaItemIndex, positionMs, bufferedPositions, totalBufferedDuration, @@ -4517,12 +4517,12 @@ public final class ExoPlayerTest { new FakeMediaSource(), createPartiallyBufferedMediaSource(/* maxBufferedPositionMs= */ 4000)); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(positionMs[0]).isEqualTo(0); assertThat(bufferedPositions[0]).isEqualTo(0); assertThat(totalBufferedDuration[0]).isEqualTo(0); - assertThat(windowIndex[1]).isEqualTo(windowIndex[0]); + assertThat(mediaItemIndex[1]).isEqualTo(mediaItemIndex[0]); assertThat(positionMs[1]).isEqualTo(positionMs[0]); assertThat(bufferedPositions[1]).isEqualTo(bufferedPositions[0]); assertThat(totalBufferedDuration[1]).isEqualTo(totalBufferedDuration[0]); @@ -4530,8 +4530,8 @@ public final class ExoPlayerTest { private void runPositionMaskingCapturingActionSchedule( PlayerRunnable actionRunnable, - int pauseWindowIndex, - int[] windowIndex, + int pauseMediaItemIndex, + int[] mediaItemIndex, long[] positionMs, long[] bufferedPosition, long[] totalBufferedDuration, @@ -4539,13 +4539,13 @@ public final class ExoPlayerTest { throws Exception { ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) - .playUntilPosition(pauseWindowIndex, /* positionMs= */ 8000) + .playUntilPosition(pauseMediaItemIndex, /* positionMs= */ 8000) .executeRunnable(actionRunnable) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndex[0] = player.getCurrentWindowIndex(); + mediaItemIndex[0] = player.getCurrentMediaItemIndex(); positionMs[0] = player.getCurrentPosition(); bufferedPosition[0] = player.getBufferedPosition(); totalBufferedDuration[0] = player.getTotalBufferedDuration(); @@ -4556,7 +4556,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndex[1] = player.getCurrentWindowIndex(); + mediaItemIndex[1] = player.getCurrentMediaItemIndex(); positionMs[1] = player.getCurrentPosition(); bufferedPosition[1] = player.getBufferedPosition(); totalBufferedDuration[1] = player.getTotalBufferedDuration(); @@ -4637,7 +4637,7 @@ public final class ExoPlayerTest { /* durationUs= */ Util.msToUs(contentDurationMs), adPlaybackState)); FakeMediaSource adsMediaSource = new FakeMediaSource(adTimeline); - int[] windowIndex = new int[] {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + int[] mediaItemIndex = new int[] {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; long[] positionMs = new long[] {C.TIME_UNSET, C.TIME_UNSET, C.INDEX_UNSET}; long[] bufferedPositionMs = new long[] {C.TIME_UNSET, C.TIME_UNSET, C.INDEX_UNSET}; long[] totalBufferedDurationMs = new long[] {C.TIME_UNSET, C.TIME_UNSET, C.INDEX_UNSET}; @@ -4653,7 +4653,7 @@ public final class ExoPlayerTest { @Override public void run(ExoPlayer player) { player.addMediaSource(/* index= */ 1, new FakeMediaSource()); - windowIndex[0] = player.getCurrentWindowIndex(); + mediaItemIndex[0] = player.getCurrentMediaItemIndex(); isPlayingAd[0] = player.isPlayingAd(); positionMs[0] = player.getCurrentPosition(); bufferedPositionMs[0] = player.getBufferedPosition(); @@ -4665,21 +4665,21 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndex[1] = player.getCurrentWindowIndex(); + mediaItemIndex[1] = player.getCurrentMediaItemIndex(); isPlayingAd[1] = player.isPlayingAd(); positionMs[1] = player.getCurrentPosition(); bufferedPositionMs[1] = player.getBufferedPosition(); totalBufferedDurationMs[1] = player.getTotalBufferedDuration(); } }) - .playUntilPosition(/* windowIndex= */ 0, /* positionMs= */ 8000) + .playUntilPosition(/* mediaItemIndex= */ 0, /* positionMs= */ 8000) .waitForPendingPlayerCommands() .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { player.addMediaSource(new FakeMediaSource()); - windowIndex[2] = player.getCurrentWindowIndex(); + mediaItemIndex[2] = player.getCurrentMediaItemIndex(); isPlayingAd[2] = player.isPlayingAd(); positionMs[2] = player.getCurrentPosition(); bufferedPositionMs[2] = player.getBufferedPosition(); @@ -4697,19 +4697,19 @@ public final class ExoPlayerTest { .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(isPlayingAd[0]).isTrue(); assertThat(positionMs[0]).isAtMost(adDurationMs); assertThat(bufferedPositionMs[0]).isEqualTo(adDurationMs); assertThat(totalBufferedDurationMs[0]).isAtLeast(adDurationMs - positionMs[0]); - assertThat(windowIndex[1]).isEqualTo(0); + assertThat(mediaItemIndex[1]).isEqualTo(0); assertThat(isPlayingAd[1]).isTrue(); assertThat(positionMs[1]).isAtMost(adDurationMs); assertThat(bufferedPositionMs[1]).isEqualTo(adDurationMs); assertThat(totalBufferedDurationMs[1]).isAtLeast(adDurationMs - positionMs[1]); - assertThat(windowIndex[2]).isEqualTo(0); + assertThat(mediaItemIndex[2]).isEqualTo(0); assertThat(isPlayingAd[2]).isFalse(); assertThat(positionMs[2]).isEqualTo(8000); assertThat(bufferedPositionMs[2]).isEqualTo(contentDurationMs); @@ -4738,7 +4738,7 @@ public final class ExoPlayerTest { /* durationUs= */ Util.msToUs(contentDurationMs), adPlaybackState)); FakeMediaSource adsMediaSource = new FakeMediaSource(adTimeline); - int[] windowIndex = new int[] {C.INDEX_UNSET, C.INDEX_UNSET}; + int[] mediaItemIndex = new int[] {C.INDEX_UNSET, C.INDEX_UNSET}; long[] positionMs = new long[] {C.TIME_UNSET, C.TIME_UNSET}; long[] bufferedPositionMs = new long[] {C.TIME_UNSET, C.TIME_UNSET}; long[] totalBufferedDurationMs = new long[] {C.TIME_UNSET, C.TIME_UNSET}; @@ -4753,8 +4753,8 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 8000); - windowIndex[0] = player.getCurrentWindowIndex(); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 8000); + mediaItemIndex[0] = player.getCurrentMediaItemIndex(); isPlayingAd[0] = player.isPlayingAd(); positionMs[0] = player.getCurrentPosition(); bufferedPositionMs[0] = player.getBufferedPosition(); @@ -4766,7 +4766,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndex[1] = player.getCurrentWindowIndex(); + mediaItemIndex[1] = player.getCurrentMediaItemIndex(); isPlayingAd[1] = player.isPlayingAd(); positionMs[1] = player.getCurrentPosition(); bufferedPositionMs[1] = player.getBufferedPosition(); @@ -4784,13 +4784,13 @@ public final class ExoPlayerTest { .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertThat(windowIndex[0]).isEqualTo(0); + assertThat(mediaItemIndex[0]).isEqualTo(0); assertThat(isPlayingAd[0]).isTrue(); assertThat(positionMs[0]).isEqualTo(0); assertThat(bufferedPositionMs[0]).isEqualTo(adDurationMs); assertThat(totalBufferedDurationMs[0]).isEqualTo(adDurationMs); - assertThat(windowIndex[1]).isEqualTo(0); + assertThat(mediaItemIndex[1]).isEqualTo(0); assertThat(isPlayingAd[1]).isTrue(); assertThat(positionMs[1]).isEqualTo(0); assertThat(bufferedPositionMs[1]).isEqualTo(adDurationMs); @@ -5332,7 +5332,7 @@ public final class ExoPlayerTest { .addMediaSources(new FakeMediaSource()) .executeRunnable( new PlaybackStateCollector(/* index= */ 3, playbackStates, timelineWindowCounts)) - .seek(/* windowIndex= */ 1, /* positionMs= */ 2000) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ 2000) .prepare() // The first expected buffering state arrives after prepare but not before. .waitForPlaybackState(Player.STATE_BUFFERING) @@ -5502,7 +5502,7 @@ public final class ExoPlayerTest { @Test public void prepareWithInvalidInitialSeek_expectEndedImmediately() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlaybackState(Player.STATE_ENDED) @@ -5510,7 +5510,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); } }) .prepare() @@ -5518,7 +5518,7 @@ public final class ExoPlayerTest { ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context) .skipSettingMediaSources() - .initialSeek(/* windowIndex= */ 1, C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, C.TIME_UNSET) .setActionSchedule(actionSchedule) .build() .start() @@ -5528,7 +5528,7 @@ public final class ExoPlayerTest { exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_ENDED); exoPlayerTestRunner.assertTimelinesSame(); exoPlayerTestRunner.assertTimelineChangeReasonsEqual(); - assertArrayEquals(new int[] {1}, currentWindowIndices); + assertArrayEquals(new int[] {1}, currentMediaItemIndices); } @Test @@ -5564,9 +5564,9 @@ public final class ExoPlayerTest { /* isAtomic= */ false, new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT)); - int[] currentWindowIndices = new int[1]; + int[] currentMediaItemIndices = new int[1]; long[] currentPlaybackPositions = new long[1]; - int seekToWindowIndex = 1; + int seekToMediaItemIndex = 1; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlaybackState(Player.STATE_BUFFERING) @@ -5575,21 +5575,21 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPlaybackPositions[0] = player.getCurrentPosition(); } }) .build(); new ExoPlayerTestRunner.Builder(context) .setMediaSources(concatenatingMediaSource) - .initialSeek(seekToWindowIndex, 5000) + .initialSeek(seekToMediaItemIndex, 5000) .setActionSchedule(actionSchedule) .build() .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); assertArrayEquals(new long[] {5_000}, currentPlaybackPositions); - assertArrayEquals(new int[] {seekToWindowIndex}, currentWindowIndices); + assertArrayEquals(new int[] {seekToMediaItemIndex}, currentMediaItemIndices); } @Test @@ -5600,10 +5600,10 @@ public final class ExoPlayerTest { /* isSeekable= */ true, /* isDynamic= */ false, /* durationUs= */ 10_000_000)); ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(/* isAtomic= */ false); - int[] currentWindowIndices = new int[2]; + int[] currentMediaItemIndices = new int[2]; long[] currentPlaybackPositions = new long[2]; long[] windowCounts = new long[2]; - int seekToWindowIndex = 1; + int seekToMediaItemIndex = 1; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlaybackState(Player.STATE_ENDED) @@ -5611,7 +5611,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPlaybackPositions[0] = player.getCurrentPosition(); windowCounts[0] = player.getCurrentTimeline().getWindowCount(); } @@ -5627,7 +5627,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); currentPlaybackPositions[1] = player.getCurrentPosition(); windowCounts[1] = player.getCurrentTimeline().getWindowCount(); } @@ -5635,14 +5635,15 @@ public final class ExoPlayerTest { .build(); new ExoPlayerTestRunner.Builder(context) .setMediaSources(concatenatingMediaSource) - .initialSeek(seekToWindowIndex, 5000) + .initialSeek(seekToMediaItemIndex, 5000) .setActionSchedule(actionSchedule) .build() .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); assertArrayEquals(new long[] {0, 2}, windowCounts); - assertArrayEquals(new int[] {seekToWindowIndex, seekToWindowIndex}, currentWindowIndices); + assertArrayEquals( + new int[] {seekToMediaItemIndex, seekToMediaItemIndex}, currentMediaItemIndices); assertArrayEquals(new long[] {5_000, 5_000}, currentPlaybackPositions); } @@ -5671,10 +5672,10 @@ public final class ExoPlayerTest { /* isSeekable= */ true, /* isDynamic= */ false, /* durationUs= */ 10_000_000)); ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(/* isAtomic= */ false); - int[] currentWindowIndices = new int[2]; + int[] currentMediaItemIndices = new int[2]; long[] currentPlaybackPositions = new long[2]; long[] windowCounts = new long[2]; - int seekToWindowIndex = 1; + int seekToMediaItemIndex = 1; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlaybackState(Player.STATE_ENDED) @@ -5682,7 +5683,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPlaybackPositions[0] = player.getCurrentPosition(); windowCounts[0] = player.getCurrentTimeline().getWindowCount(); } @@ -5698,7 +5699,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); currentPlaybackPositions[1] = player.getCurrentPosition(); windowCounts[1] = player.getCurrentTimeline().getWindowCount(); } @@ -5707,14 +5708,15 @@ public final class ExoPlayerTest { new ExoPlayerTestRunner.Builder(context) .setMediaSources(concatenatingMediaSource) .setUseLazyPreparation(/* useLazyPreparation= */ true) - .initialSeek(seekToWindowIndex, 5000) + .initialSeek(seekToMediaItemIndex, 5000) .setActionSchedule(actionSchedule) .build() .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); assertArrayEquals(new long[] {0, 2}, windowCounts); - assertArrayEquals(new int[] {seekToWindowIndex, seekToWindowIndex}, currentWindowIndices); + assertArrayEquals( + new int[] {seekToMediaItemIndex, seekToMediaItemIndex}, currentMediaItemIndices); assertArrayEquals(new long[] {5_000, 5_000}, currentPlaybackPositions); } @@ -5875,19 +5877,19 @@ public final class ExoPlayerTest { } @Test - public void setMediaSources_empty_whenEmpty_correctMaskingWindowIndex() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + public void setMediaSources_empty_whenEmpty_correctMaskingMediaItemIndex() throws Exception { + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); List listOfTwo = ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()); player.addMediaSources(/* index= */ 0, listOfTwo); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) .prepare() @@ -5896,7 +5898,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); } }) .build(); @@ -5907,12 +5909,12 @@ public final class ExoPlayerTest { .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {0, 0, 0}, currentWindowIndices); + assertArrayEquals(new int[] {0, 0, 0}, currentMediaItemIndices); } @Test public void setMediaItems_resetPosition_resetsPosition() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] currentPositions = {C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) @@ -5921,14 +5923,14 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ 1000); - currentWindowIndices[0] = player.getCurrentWindowIndex(); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ 1000); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPositions[0] = player.getCurrentPosition(); List listOfTwo = ImmutableList.of( MediaItem.fromUri(Uri.EMPTY), MediaItem.fromUri(Uri.EMPTY)); player.setMediaItems(listOfTwo, /* resetPosition= */ true); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); currentPositions[1] = player.getCurrentPosition(); } }) @@ -5942,14 +5944,14 @@ public final class ExoPlayerTest { .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 0}, currentWindowIndices); + assertArrayEquals(new int[] {1, 0}, currentMediaItemIndices); assertArrayEquals(new long[] {1000, 0}, currentPositions); } @Test - public void setMediaSources_empty_whenEmpty_validInitialSeek_correctMaskingWindowIndex() + public void setMediaSources_empty_whenEmpty_validInitialSeek_correctMaskingMediaItemIndex() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) // Wait for initial seek to be fully handled by internal player. @@ -5959,11 +5961,11 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); List listOfTwo = ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()); player.addMediaSources(/* index= */ 0, listOfTwo); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) .prepare() @@ -5972,25 +5974,25 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); } }) .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, C.TIME_UNSET) .setMediaSources(new ConcatenatingMediaSource()) .setActionSchedule(actionSchedule) .build() .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 1, 1}, currentWindowIndices); + assertArrayEquals(new int[] {1, 1, 1}, currentMediaItemIndices); } @Test - public void setMediaSources_empty_whenEmpty_invalidInitialSeek_correctMaskingWindowIndex() + public void setMediaSources_empty_whenEmpty_invalidInitialSeek_correctMaskingMediaItemIndex() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) // Wait for initial seek to be fully handled by internal player. @@ -6000,11 +6002,11 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); List listOfTwo = ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()); player.addMediaSources(/* index= */ 0, listOfTwo); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) .prepare() @@ -6013,24 +6015,26 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); } }) .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 4, C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 4, C.TIME_UNSET) .setMediaSources(new ConcatenatingMediaSource()) .setActionSchedule(actionSchedule) .build() .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {4, 0, 0}, currentWindowIndices); + assertArrayEquals(new int[] {4, 0, 0}, currentMediaItemIndices); } @Test - public void setMediaSources_whenEmpty_correctMaskingWindowIndex() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + public void setMediaSources_whenEmpty_correctMaskingMediaItemIndex() throws Exception { + final int[] currentMediaItemIndices = { + C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET + }; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlaybackState(Player.STATE_READY) @@ -6038,18 +6042,18 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - // Increase current window index. + // Increase current media item index. player.addMediaSource(/* index= */ 0, new FakeMediaSource()); - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); } }) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - // Current window index is unchanged. + // Current media item index is unchanged. player.addMediaSource(/* index= */ 2, new FakeMediaSource()); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) .executeRunnable( @@ -6059,9 +6063,9 @@ public final class ExoPlayerTest { MediaSource mediaSource = new FakeMediaSource(); ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(mediaSource, mediaSource, mediaSource); - // Increase current window with multi window source. + // Increase current media item with multi media item source. player.addMediaSource(/* index= */ 0, concatenatingMediaSource); - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); } }) .executeRunnable( @@ -6070,9 +6074,9 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { ConcatenatingMediaSource concatenatingMediaSource = new ConcatenatingMediaSource(); - // Current window index is unchanged when adding empty source. + // Current media item index is unchanged when adding empty source. player.addMediaSource(/* index= */ 0, concatenatingMediaSource); - currentWindowIndices[3] = player.getCurrentWindowIndex(); + currentMediaItemIndices[3] = player.getCurrentMediaItemIndex(); } }) .build(); @@ -6083,7 +6087,7 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 1, 4, 4}, currentWindowIndices); + assertArrayEquals(new int[] {1, 1, 4, 4}, currentMediaItemIndices); } @Test @@ -6092,7 +6096,7 @@ public final class ExoPlayerTest { MediaSource firstMediaSource = new FakeMediaSource(firstTimeline); Timeline secondTimeline = new FakeTimeline(/* windowCount= */ 1, new Object()); MediaSource secondMediaSource = new FakeMediaSource(secondTimeline); - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; final long[] currentPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; ActionSchedule actionSchedule = @@ -6104,12 +6108,12 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPositions[0] = player.getCurrentPosition(); bufferedPositions[0] = player.getBufferedPosition(); - // Increase current window index. + // Increase current media item index. player.addMediaSource(/* index= */ 0, secondMediaSource); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); currentPositions[1] = player.getCurrentPosition(); bufferedPositions[1] = player.getBufferedPosition(); } @@ -6120,28 +6124,28 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); currentPositions[2] = player.getCurrentPosition(); bufferedPositions[2] = player.getBufferedPosition(); } }) .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, 2000) + .initialSeek(/* mediaItemIndex= */ 1, 2000) .setMediaSources(firstMediaSource) .setActionSchedule(actionSchedule) .build() .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 2, 2}, currentWindowIndices); + assertArrayEquals(new int[] {1, 2, 2}, currentMediaItemIndices); assertArrayEquals(new long[] {2000, 2000, 2000}, currentPositions); assertArrayEquals(new long[] {2000, 2000, 2000}, bufferedPositions); } @Test public void setMediaSources_whenEmpty_invalidInitialSeek_correctMasking() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; final long[] currentPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; ActionSchedule actionSchedule = @@ -6153,12 +6157,12 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPositions[0] = player.getCurrentPosition(); bufferedPositions[0] = player.getBufferedPosition(); - // Increase current window index. + // Increase current media item index. player.addMediaSource(/* index= */ 0, new FakeMediaSource()); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); currentPositions[1] = player.getCurrentPosition(); bufferedPositions[1] = player.getBufferedPosition(); } @@ -6169,7 +6173,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); currentPositions[2] = player.getCurrentPosition(); bufferedPositions[2] = player.getBufferedPosition(); } @@ -6177,21 +6181,21 @@ public final class ExoPlayerTest { .waitForPlaybackState(Player.STATE_ENDED) .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, 2000) + .initialSeek(/* mediaItemIndex= */ 1, 2000) .setMediaSources(new FakeMediaSource()) .setActionSchedule(actionSchedule) .build() .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {0, 1, 1}, currentWindowIndices); + assertArrayEquals(new int[] {0, 1, 1}, currentMediaItemIndices); assertArrayEquals(new long[] {0, 0, 0}, currentPositions); assertArrayEquals(new long[] {0, 0, 0}, bufferedPositions); } @Test - public void setMediaSources_correctMaskingWindowIndex() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + public void setMediaSources_correctMaskingMediaItemIndex() throws Exception { + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForTimelineChanged() @@ -6199,10 +6203,10 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); - // Increase current window index. + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); + // Increase current media item index. player.addMediaSource(/* index= */ 0, new FakeMediaSource()); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) .waitForTimelineChanged() @@ -6210,7 +6214,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); } }) .build(); @@ -6221,7 +6225,7 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {0, 1, 1}, currentWindowIndices); + assertArrayEquals(new int[] {0, 1, 1}, currentMediaItemIndices); } @Test @@ -6278,7 +6282,7 @@ public final class ExoPlayerTest { .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_ENDED); assertArrayEquals( new int[] {Player.STATE_IDLE, Player.STATE_IDLE, Player.STATE_IDLE, Player.STATE_IDLE}, @@ -6314,14 +6318,14 @@ public final class ExoPlayerTest { .build(); ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) .setMediaSources(new ConcatenatingMediaSource()) .setActionSchedule(actionSchedule) .build() .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED); assertArrayEquals(new int[] {Player.STATE_IDLE}, maskingPlaybackStates); @@ -6356,7 +6360,7 @@ public final class ExoPlayerTest { .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED); assertArrayEquals(new int[] {Player.STATE_IDLE}, maskingPlaybackStates); @@ -6392,7 +6396,7 @@ public final class ExoPlayerTest { .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED); assertArrayEquals(new int[] {Player.STATE_IDLE}, maskingPlaybackStates); @@ -6464,7 +6468,7 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_ENDED, Player.STATE_BUFFERING, @@ -6509,14 +6513,14 @@ public final class ExoPlayerTest { .build(); ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) .setMediaSources(new ConcatenatingMediaSource()) .setActionSchedule(actionSchedule) .build() .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual(Player.STATE_ENDED); assertArrayEquals(new int[] {Player.STATE_ENDED}, maskingPlaybackStates); exoPlayerTestRunner.assertTimelineChangeReasonsEqual( @@ -6552,7 +6556,7 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED); assertArrayEquals(new int[] {Player.STATE_ENDED}, maskingPlaybackStates); @@ -6591,7 +6595,7 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_BUFFERING, Player.STATE_READY, Player.STATE_ENDED); assertArrayEquals(new int[] {Player.STATE_ENDED}, maskingPlaybackStates); @@ -6625,7 +6629,8 @@ public final class ExoPlayerTest { } }) .waitForPlaybackState(Player.STATE_ENDED) - .setMediaSources(/* windowIndex= */ 0, /* positionMs= */ C.TIME_UNSET, firstMediaSource) + .setMediaSources( + /* mediaItemIndex= */ 0, /* positionMs= */ C.TIME_UNSET, firstMediaSource) .waitForPlaybackState(Player.STATE_READY) .executeRunnable( new PlayerRunnable() { @@ -6639,7 +6644,8 @@ public final class ExoPlayerTest { } }) .waitForPlaybackState(Player.STATE_ENDED) - .setMediaSources(/* windowIndex= */ 0, /* positionMs= */ C.TIME_UNSET, firstMediaSource) + .setMediaSources( + /* mediaItemIndex= */ 0, /* positionMs= */ C.TIME_UNSET, firstMediaSource) .waitForPlaybackState(Player.STATE_READY) .executeRunnable( new PlayerRunnable() { @@ -6652,7 +6658,8 @@ public final class ExoPlayerTest { } }) .waitForPlaybackState(Player.STATE_READY) - .setMediaSources(/* windowIndex= */ 0, /* positionMs= */ C.TIME_UNSET, firstMediaSource) + .setMediaSources( + /* mediaItemIndex= */ 0, /* positionMs= */ C.TIME_UNSET, firstMediaSource) .waitForPlaybackState(Player.STATE_READY) .executeRunnable( new PlayerRunnable() { @@ -6676,7 +6683,7 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_BUFFERING, Player.STATE_READY, // Ready after initial prepare. @@ -6737,7 +6744,8 @@ public final class ExoPlayerTest { } }) .waitForTimelineChanged() - .setMediaSources(/* windowIndex= */ 0, /* positionMs= */ C.TIME_UNSET, firstMediaSource) + .setMediaSources( + /* mediaItemIndex= */ 0, /* positionMs= */ C.TIME_UNSET, firstMediaSource) .waitForPlaybackState(Player.STATE_READY) .play() .waitForPlaybackState(Player.STATE_ENDED) @@ -6745,14 +6753,14 @@ public final class ExoPlayerTest { ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context) .setExpectedPlayerEndedCount(/* expectedPlayerEndedCount= */ 2) - .initialSeek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) .setMediaSources(new ConcatenatingMediaSource()) .setActionSchedule(actionSchedule) .build() .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_ENDED, // Empty source has been prepared. Player.STATE_BUFFERING, // After setting another source. @@ -6788,7 +6796,7 @@ public final class ExoPlayerTest { .build(); new ExoPlayerTestRunner.Builder(context) .skipSettingMediaSources() - .initialSeek(/* windowIndex= */ 0, /* positionMs= */ 2000) + .initialSeek(/* mediaItemIndex= */ 0, /* positionMs= */ 2000) .setActionSchedule(actionSchedule) .build() .start(/* doPrepare= */ false) @@ -6800,8 +6808,8 @@ public final class ExoPlayerTest { @Test public void addMediaSources_skipSettingMediaItems_validInitialSeek_correctMasking() throws Exception { - final int[] currentWindowIndices = new int[5]; - Arrays.fill(currentWindowIndices, C.INDEX_UNSET); + final int[] currentMediaItemIndices = new int[5]; + Arrays.fill(currentMediaItemIndices, C.INDEX_UNSET); final long[] currentPositions = new long[3]; Arrays.fill(currentPositions, C.TIME_UNSET); final long[] bufferedPositions = new long[3]; @@ -6815,18 +6823,18 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); // If the timeline is empty masking variables are used. currentPositions[0] = player.getCurrentPosition(); bufferedPositions[0] = player.getBufferedPosition(); player.addMediaSource(/* index= */ 0, new ConcatenatingMediaSource()); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); player.addMediaSource( /* index= */ 0, new FakeMediaSource(new FakeTimeline(/* windowCount= */ 2))); - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); player.addMediaSource(/* index= */ 0, new FakeMediaSource()); - currentWindowIndices[3] = player.getCurrentWindowIndex(); + currentMediaItemIndices[3] = player.getCurrentMediaItemIndex(); // With a non-empty timeline, we mask the periodId in the playback info. currentPositions[1] = player.getCurrentPosition(); bufferedPositions[1] = player.getBufferedPosition(); @@ -6838,7 +6846,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[4] = player.getCurrentWindowIndex(); + currentMediaItemIndices[4] = player.getCurrentMediaItemIndex(); // Finally original playbackInfo coming from EPII is used. currentPositions[2] = player.getCurrentPosition(); bufferedPositions[2] = player.getBufferedPosition(); @@ -6847,13 +6855,13 @@ public final class ExoPlayerTest { .build(); new ExoPlayerTestRunner.Builder(context) .skipSettingMediaSources() - .initialSeek(/* windowIndex= */ 1, 2000) + .initialSeek(/* mediaItemIndex= */ 1, 2000) .setActionSchedule(actionSchedule) .build() .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 1, 1, 2, 2}, currentWindowIndices); + assertArrayEquals(new int[] {1, 1, 1, 2, 2}, currentMediaItemIndices); assertThat(currentPositions[0]).isEqualTo(2000); assertThat(currentPositions[1]).isEqualTo(2000); assertThat(currentPositions[2]).isAtLeast(2000); @@ -6864,9 +6872,9 @@ public final class ExoPlayerTest { @Test public void - testAddMediaSources_skipSettingMediaItems_invalidInitialSeek_correctMaskingWindowIndex() + testAddMediaSources_skipSettingMediaItems_invalidInitialSeek_correctMaskingMediaItemIndex() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) // Wait for initial seek to be fully handled by internal player. @@ -6876,9 +6884,9 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); player.addMediaSource(new FakeMediaSource()); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) .prepare() @@ -6887,28 +6895,28 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); } }) .build(); new ExoPlayerTestRunner.Builder(context) .skipSettingMediaSources() - .initialSeek(/* windowIndex= */ 1, C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, C.TIME_UNSET) .setActionSchedule(actionSchedule) .build() .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 0, 0}, currentWindowIndices); + assertArrayEquals(new int[] {1, 0, 0}, currentMediaItemIndices); } @Test - public void moveMediaItems_correctMaskingWindowIndex() throws Exception { + public void moveMediaItems_correctMaskingMediaItemIndex() throws Exception { Timeline timeline = new FakeTimeline(); MediaSource firstMediaSource = new FakeMediaSource(timeline); MediaSource secondMediaSource = new FakeMediaSource(timeline); MediaSource thirdMediaSource = new FakeMediaSource(timeline); - final int[] currentWindowIndices = { + final int[] currentMediaItemIndices = { C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET }; ActionSchedule actionSchedule = @@ -6920,7 +6928,7 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Move the current item down in the playlist. player.moveMediaItems(/* fromIndex= */ 0, /* toIndex= */ 2, /* newIndex= */ 1); - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); } }) .executeRunnable( @@ -6929,17 +6937,17 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Move the current item up in the playlist. player.moveMediaItems(/* fromIndex= */ 1, /* toIndex= */ 3, /* newIndex= */ 0); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) - .seek(/* windowIndex= */ 2, C.TIME_UNSET) + .seek(/* mediaItemIndex= */ 2, C.TIME_UNSET) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { // Move items from before to behind the current item. player.moveMediaItems(/* fromIndex= */ 0, /* toIndex= */ 2, /* newIndex= */ 1); - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); } }) .executeRunnable( @@ -6948,7 +6956,7 @@ public final class ExoPlayerTest { public void run(ExoPlayer player) { // Move items from behind to before the current item. player.moveMediaItems(/* fromIndex= */ 1, /* toIndex= */ 3, /* newIndex= */ 0); - currentWindowIndices[3] = player.getCurrentWindowIndex(); + currentMediaItemIndices[3] = player.getCurrentMediaItemIndex(); } }) .executeRunnable( @@ -6956,20 +6964,20 @@ public final class ExoPlayerTest { @Override public void run(ExoPlayer player) { // Move items from before to before the current item. - // No change in currentWindowIndex. + // No change in currentMediaItemIndex. player.moveMediaItems(/* fromIndex= */ 0, /* toIndex= */ 1, /* newIndex= */ 1); - currentWindowIndices[4] = player.getCurrentWindowIndex(); + currentMediaItemIndices[4] = player.getCurrentMediaItemIndex(); } }) - .seek(/* windowIndex= */ 0, C.TIME_UNSET) + .seek(/* mediaItemIndex= */ 0, C.TIME_UNSET) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { // Move items from behind to behind the current item. - // No change in currentWindowIndex. + // No change in currentMediaItemIndex. player.moveMediaItems(/* fromIndex= */ 1, /* toIndex= */ 2, /* newIndex= */ 2); - currentWindowIndices[5] = player.getCurrentWindowIndex(); + currentMediaItemIndices[5] = player.getCurrentMediaItemIndex(); } }) .build(); @@ -6980,12 +6988,12 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 0, 0, 2, 2, 0}, currentWindowIndices); + assertArrayEquals(new int[] {1, 0, 0, 2, 2, 0}, currentMediaItemIndices); } @Test - public void moveMediaItems_unprepared_correctMaskingWindowIndex() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; + public void moveMediaItems_unprepared_correctMaskingMediaItemIndex() throws Exception { + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForTimelineChanged() @@ -6993,10 +7001,10 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - // Increase current window index. - currentWindowIndices[0] = player.getCurrentWindowIndex(); + // Increase current media item index. + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); player.moveMediaItem(/* currentIndex= */ 0, /* newIndex= */ 1); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) .prepare() @@ -7005,7 +7013,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[2] = player.getCurrentWindowIndex(); + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); } }) .build(); @@ -7016,12 +7024,12 @@ public final class ExoPlayerTest { .start(/* doPrepare= */ false) .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {0, 1, 1}, currentWindowIndices); + assertArrayEquals(new int[] {0, 1, 1}, currentMediaItemIndices); } @Test - public void removeMediaItems_correctMaskingWindowIndex() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; + public void removeMediaItems_correctMaskingMediaItemIndex() throws Exception { + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlaybackState(Player.STATE_BUFFERING) @@ -7029,27 +7037,27 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - // Decrease current window index. - currentWindowIndices[0] = player.getCurrentWindowIndex(); + // Decrease current media item index. + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); player.removeMediaItem(/* index= */ 0); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); } }) .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) .setMediaSources(new FakeMediaSource(), new FakeMediaSource()) .setActionSchedule(actionSchedule) .build() .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 0}, currentWindowIndices); + assertArrayEquals(new int[] {1, 0}, currentMediaItemIndices); } @Test public void removeMediaItems_currentItemRemoved_correctMasking() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; final long[] currentPositions = {C.TIME_UNSET, C.TIME_UNSET}; final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET}; ActionSchedule actionSchedule = @@ -7060,25 +7068,25 @@ public final class ExoPlayerTest { @Override public void run(ExoPlayer player) { // Remove the current item. - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPositions[0] = player.getCurrentPosition(); bufferedPositions[0] = player.getBufferedPosition(); player.removeMediaItem(/* index= */ 1); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); currentPositions[1] = player.getCurrentPosition(); bufferedPositions[1] = player.getBufferedPosition(); } }) .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, /* positionMs= */ 5000) + .initialSeek(/* mediaItemIndex= */ 1, /* positionMs= */ 5000) .setMediaSources(new FakeMediaSource(), new FakeMediaSource(), new FakeMediaSource()) .setActionSchedule(actionSchedule) .build() .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 1}, currentWindowIndices); + assertArrayEquals(new int[] {1, 1}, currentMediaItemIndices); assertThat(currentPositions[0]).isAtLeast(5000L); assertThat(bufferedPositions[0]).isAtLeast(5000L); assertThat(currentPositions[1]).isEqualTo(0); @@ -7095,8 +7103,8 @@ public final class ExoPlayerTest { MediaSource thirdMediaSource = new FakeMediaSource(thirdTimeline); Timeline fourthTimeline = new FakeTimeline(/* windowCount= */ 1, 3L); MediaSource fourthMediaSource = new FakeMediaSource(fourthTimeline); - final int[] currentWindowIndices = new int[9]; - Arrays.fill(currentWindowIndices, C.INDEX_UNSET); + final int[] currentMediaItemIndices = new int[9]; + Arrays.fill(currentMediaItemIndices, C.INDEX_UNSET); final int[] maskingPlaybackStates = new int[4]; Arrays.fill(maskingPlaybackStates, C.INDEX_UNSET); final long[] currentPositions = new long[3]; @@ -7111,14 +7119,14 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - // Expect the current window index to be 2 after seek. - currentWindowIndices[0] = player.getCurrentWindowIndex(); + // Expect the current media item index to be 2 after seek. + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPositions[0] = player.getCurrentPosition(); bufferedPositions[0] = player.getBufferedPosition(); player.removeMediaItem(/* index= */ 2); - // Expect the current window index to be 0 + // Expect the current media item index to be 0 // (default position of timeline after not finding subsequent period). - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); // Transition to ENDED. maskingPlaybackStates[0] = player.getPlaybackState(); currentPositions[1] = player.getCurrentPosition(); @@ -7130,12 +7138,12 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - // Expects the current window index still on 0. - currentWindowIndices[2] = player.getCurrentWindowIndex(); + // Expects the current media item index still on 0. + currentMediaItemIndices[2] = player.getCurrentMediaItemIndex(); // Insert an item at begin when the playlist is not empty. player.addMediaSource(/* index= */ 0, thirdMediaSource); - // Expects the current window index to be (0 + 1) after insertion at begin. - currentWindowIndices[3] = player.getCurrentWindowIndex(); + // Expects the current media item index to be (0 + 1) after insertion at begin. + currentMediaItemIndices[3] = player.getCurrentMediaItemIndex(); // Remains in ENDED. maskingPlaybackStates[1] = player.getPlaybackState(); currentPositions[2] = player.getCurrentPosition(); @@ -7147,12 +7155,12 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[4] = player.getCurrentWindowIndex(); - // Implicit seek to the current window index, which is out of bounds in new + currentMediaItemIndices[4] = player.getCurrentMediaItemIndex(); + // Implicit seek to the current media item index, which is out of bounds in new // timeline. player.setMediaSource(fourthMediaSource, /* resetPosition= */ false); // 0 after reset. - currentWindowIndices[5] = player.getCurrentWindowIndex(); + currentMediaItemIndices[5] = player.getCurrentMediaItemIndex(); // Invalid seek, so we remain in ENDED. maskingPlaybackStates[2] = player.getPlaybackState(); } @@ -7162,11 +7170,11 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[6] = player.getCurrentWindowIndex(); + currentMediaItemIndices[6] = player.getCurrentMediaItemIndex(); // Explicit seek to (0, C.TIME_UNSET). Player transitions to BUFFERING. player.setMediaSource(fourthMediaSource, /* startPositionMs= */ 5000); // 0 after explicit seek. - currentWindowIndices[7] = player.getCurrentWindowIndex(); + currentMediaItemIndices[7] = player.getCurrentMediaItemIndex(); // Transitions from ENDED to BUFFERING after explicit seek. maskingPlaybackStates[3] = player.getPlaybackState(); } @@ -7176,14 +7184,14 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - // Check whether actual window index is equal masking index from above. - currentWindowIndices[8] = player.getCurrentWindowIndex(); + // Check whether actual media item index is equal masking index from above. + currentMediaItemIndices[8] = player.getCurrentMediaItemIndex(); } }) .build(); ExoPlayerTestRunner exoPlayerTestRunner = new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 2, /* positionMs= */ C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 2, /* positionMs= */ C.TIME_UNSET) .setExpectedPlayerEndedCount(2) .setMediaSources(firstMediaSource, secondMediaSource, thirdMediaSource) .setActionSchedule(actionSchedule) @@ -7191,23 +7199,23 @@ public final class ExoPlayerTest { .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - // Expect reset of masking to first window. + // Expect reset of masking to first media item. exoPlayerTestRunner.assertPlaybackStatesEqual( Player.STATE_BUFFERING, Player.STATE_READY, // Ready after initial prepare. - Player.STATE_ENDED, // ended after removing current window index + Player.STATE_ENDED, // ended after removing current media item index Player.STATE_BUFFERING, // buffers after set items with seek Player.STATE_READY, Player.STATE_ENDED); assertArrayEquals( new int[] { - Player.STATE_ENDED, // ended after removing current window index + Player.STATE_ENDED, // ended after removing current media item index Player.STATE_ENDED, // adding items does not change state Player.STATE_ENDED, // set items with seek to current position. Player.STATE_BUFFERING }, // buffers after set items with seek maskingPlaybackStates); - assertArrayEquals(new int[] {2, 0, 0, 1, 1, 0, 0, 0, 0}, currentWindowIndices); + assertArrayEquals(new int[] {2, 0, 0, 1, 1, 0, 0, 0, 0}, currentMediaItemIndices); assertThat(currentPositions[0]).isEqualTo(0); assertThat(currentPositions[1]).isEqualTo(0); assertThat(currentPositions[2]).isEqualTo(0); @@ -7221,7 +7229,7 @@ public final class ExoPlayerTest { throws Exception { ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) - .seek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .seek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) .waitForPendingPlayerCommands() .removeMediaItem(/* index= */ 1) .prepare() @@ -7241,7 +7249,7 @@ public final class ExoPlayerTest { @Test public void clearMediaItems_correctMasking() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; final int[] maskingPlaybackState = {C.INDEX_UNSET}; final long[] currentPosition = {C.TIME_UNSET, C.TIME_UNSET}; final long[] bufferedPosition = {C.TIME_UNSET, C.TIME_UNSET}; @@ -7249,16 +7257,16 @@ public final class ExoPlayerTest { new ActionSchedule.Builder(TAG) .pause() .waitForPlaybackState(Player.STATE_BUFFERING) - .playUntilPosition(/* windowIndex= */ 1, /* positionMs= */ 150) + .playUntilPosition(/* mediaItemIndex= */ 1, /* positionMs= */ 150) .executeRunnable( new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentPosition[0] = player.getCurrentPosition(); bufferedPosition[0] = player.getBufferedPosition(); player.clearMediaItems(); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); currentPosition[1] = player.getCurrentPosition(); bufferedPosition[1] = player.getBufferedPosition(); maskingPlaybackState[0] = player.getPlaybackState(); @@ -7266,25 +7274,25 @@ public final class ExoPlayerTest { }) .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) .setMediaSources(new FakeMediaSource(), new FakeMediaSource()) .setActionSchedule(actionSchedule) .build() .start() .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertArrayEquals(new int[] {1, 0}, currentWindowIndices); + assertArrayEquals(new int[] {1, 0}, currentMediaItemIndices); assertThat(currentPosition[0]).isAtLeast(150); assertThat(currentPosition[1]).isEqualTo(0); assertThat(bufferedPosition[0]).isAtLeast(150); assertThat(bufferedPosition[1]).isEqualTo(0); - assertArrayEquals(new int[] {1, 0}, currentWindowIndices); + assertArrayEquals(new int[] {1, 0}, currentMediaItemIndices); assertArrayEquals(new int[] {Player.STATE_ENDED}, maskingPlaybackState); } @Test - public void clearMediaItems_unprepared_correctMaskingWindowIndex_notEnded() throws Exception { - final int[] currentWindowIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; + public void clearMediaItems_unprepared_correctMaskingMediaItemIndex_notEnded() throws Exception { + final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET}; final int[] currentStates = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) @@ -7295,10 +7303,10 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - currentWindowIndices[0] = player.getCurrentWindowIndex(); + currentMediaItemIndices[0] = player.getCurrentMediaItemIndex(); currentStates[0] = player.getPlaybackState(); player.clearMediaItems(); - currentWindowIndices[1] = player.getCurrentWindowIndex(); + currentMediaItemIndices[1] = player.getCurrentMediaItemIndex(); currentStates[1] = player.getPlaybackState(); } }) @@ -7313,7 +7321,7 @@ public final class ExoPlayerTest { }) .build(); new ExoPlayerTestRunner.Builder(context) - .initialSeek(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET) + .initialSeek(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET) .setMediaSources(new FakeMediaSource(), new FakeMediaSource()) .setActionSchedule(actionSchedule) .build() @@ -7322,7 +7330,7 @@ public final class ExoPlayerTest { .blockUntilEnded(TIMEOUT_MS); assertArrayEquals( new int[] {Player.STATE_IDLE, Player.STATE_IDLE, Player.STATE_ENDED}, currentStates); - assertArrayEquals(new int[] {1, 0}, currentWindowIndices); + assertArrayEquals(new int[] {1, 0}, currentMediaItemIndices); } @Test @@ -7351,7 +7359,7 @@ public final class ExoPlayerTest { AtomicReference timelineAfterError = new AtomicReference<>(); AtomicReference trackInfosAfterError = new AtomicReference<>(); AtomicReference trackSelectionsAfterError = new AtomicReference<>(); - AtomicInteger windowIndexAfterError = new AtomicInteger(); + AtomicInteger mediaItemIndexAfterError = new AtomicInteger(); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .executeRunnable( @@ -7365,7 +7373,7 @@ public final class ExoPlayerTest { timelineAfterError.set(player.getCurrentTimeline()); trackInfosAfterError.set(player.getCurrentTracksInfo()); trackSelectionsAfterError.set(player.getCurrentTrackSelections()); - windowIndexAfterError.set(player.getCurrentWindowIndex()); + mediaItemIndexAfterError.set(player.getCurrentMediaItemIndex()); } }); } @@ -7392,7 +7400,7 @@ public final class ExoPlayerTest { .blockUntilEnded(TIMEOUT_MS)); assertThat(timelineAfterError.get().getWindowCount()).isEqualTo(1); - assertThat(windowIndexAfterError.get()).isEqualTo(0); + assertThat(mediaItemIndexAfterError.get()).isEqualTo(0); assertThat(trackInfosAfterError.get().getTrackGroupInfos()).hasSize(1); assertThat(trackInfosAfterError.get().getTrackGroupInfos().get(0).getTrackGroup().getFormat(0)) .isEqualTo(ExoPlayerTestRunner.AUDIO_FORMAT); @@ -7404,7 +7412,7 @@ public final class ExoPlayerTest { public void seekToCurrentPosition_inEndedState_switchesToBufferingStateAndContinuesPlayback() throws Exception { MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount = */ 1)); - AtomicInteger windowIndexAfterFinalEndedState = new AtomicInteger(); + AtomicInteger mediaItemIndexAfterFinalEndedState = new AtomicInteger(); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlaybackState(Player.STATE_ENDED) @@ -7422,7 +7430,7 @@ public final class ExoPlayerTest { new PlayerRunnable() { @Override public void run(ExoPlayer player) { - windowIndexAfterFinalEndedState.set(player.getCurrentWindowIndex()); + mediaItemIndexAfterFinalEndedState.set(player.getCurrentMediaItemIndex()); } }) .build(); @@ -7434,7 +7442,7 @@ public final class ExoPlayerTest { .blockUntilActionScheduleFinished(TIMEOUT_MS) .blockUntilEnded(TIMEOUT_MS); - assertThat(windowIndexAfterFinalEndedState.get()).isEqualTo(1); + assertThat(mediaItemIndexAfterFinalEndedState.get()).isEqualTo(1); } @Test @@ -7448,7 +7456,7 @@ public final class ExoPlayerTest { MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(timelineWindowDefinition)); AtomicInteger playbackStateAfterPause = new AtomicInteger(C.INDEX_UNSET); AtomicLong positionAfterPause = new AtomicLong(C.TIME_UNSET); - AtomicInteger windowIndexAfterPause = new AtomicInteger(C.INDEX_UNSET); + AtomicInteger mediaItemIndexAfterPause = new AtomicInteger(C.INDEX_UNSET); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlayWhenReady(true) @@ -7458,7 +7466,7 @@ public final class ExoPlayerTest { @Override public void run(ExoPlayer player) { playbackStateAfterPause.set(player.getPlaybackState()); - windowIndexAfterPause.set(player.getCurrentWindowIndex()); + mediaItemIndexAfterPause.set(player.getCurrentMediaItemIndex()); positionAfterPause.set(player.getContentPosition()); } }) @@ -7473,7 +7481,7 @@ public final class ExoPlayerTest { .blockUntilEnded(TIMEOUT_MS); assertThat(playbackStateAfterPause.get()).isEqualTo(Player.STATE_READY); - assertThat(windowIndexAfterPause.get()).isEqualTo(0); + assertThat(mediaItemIndexAfterPause.get()).isEqualTo(0); assertThat(positionAfterPause.get()).isEqualTo(10_000); } @@ -7487,7 +7495,7 @@ public final class ExoPlayerTest { MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(timelineWindowDefinition)); AtomicInteger playbackStateAfterPause = new AtomicInteger(C.INDEX_UNSET); AtomicLong positionAfterPause = new AtomicLong(C.TIME_UNSET); - AtomicInteger windowIndexAfterPause = new AtomicInteger(C.INDEX_UNSET); + AtomicInteger mediaItemIndexAfterPause = new AtomicInteger(C.INDEX_UNSET); ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG) .waitForPlayWhenReady(true) @@ -7497,7 +7505,7 @@ public final class ExoPlayerTest { @Override public void run(ExoPlayer player) { playbackStateAfterPause.set(player.getPlaybackState()); - windowIndexAfterPause.set(player.getCurrentWindowIndex()); + mediaItemIndexAfterPause.set(player.getCurrentMediaItemIndex()); positionAfterPause.set(player.getContentPosition()); } }) @@ -7512,7 +7520,7 @@ public final class ExoPlayerTest { .blockUntilEnded(TIMEOUT_MS); assertThat(playbackStateAfterPause.get()).isEqualTo(Player.STATE_ENDED); - assertThat(windowIndexAfterPause.get()).isEqualTo(0); + assertThat(mediaItemIndexAfterPause.get()).isEqualTo(0); assertThat(positionAfterPause.get()).isEqualTo(10_000); } @@ -7846,7 +7854,7 @@ public final class ExoPlayerTest { firstMediaSource.setNewSourceInfo(timelineWithOffsets); // Wait until player transitions to second source (which also has non-zero offsets). runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION); - assertThat(player.getCurrentWindowIndex()).isEqualTo(1); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1); player.release(); assertThat(rendererStreamOffsetsUs).hasSize(2); @@ -8102,7 +8110,7 @@ public final class ExoPlayerTest { player.prepare(); runUntilPlaybackState(player, Player.STATE_READY); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ 2000); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ 2000); assertThat(reportedMediaItems) .containsExactly(mediaSource1.getMediaItem(), mediaSource2.getMediaItem()) @@ -8134,7 +8142,7 @@ public final class ExoPlayerTest { player.prepare(); runUntilPlaybackState(player, Player.STATE_READY); - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 2000); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 2000); assertThat(reportedMediaItems).containsExactly(mediaSource1.getMediaItem()).inOrder(); assertThat(reportedTransitionReasons) @@ -8371,7 +8379,7 @@ public final class ExoPlayerTest { player.addMediaSources( ImmutableList.of( new FakeMediaSource(), new FakeMediaSource(adTimeline), new FakeMediaSource())); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ 0); player.prepare(); runUntilPlaybackState(player, Player.STATE_READY); @@ -8451,7 +8459,7 @@ public final class ExoPlayerTest { ExoPlayer player = new TestExoPlayerBuilder(context).build(); player.addMediaSource(new FakeMediaSource(timelineWithUnseekableLiveWindow)); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ 0); player.prepare(); runUntilPlaybackState(player, Player.STATE_READY); @@ -8507,14 +8515,14 @@ public final class ExoPlayerTest { // Check that there were no other calls to onAvailableCommandsChanged. verify(mockListener).onAvailableCommandsChanged(any()); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ 0); verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousAndNextWindow); verify(mockListener, times(2)).onAvailableCommandsChanged(any()); - player.seekTo(/* windowIndex= */ 2, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 2, /* positionMs= */ 0); verify(mockListener, times(2)).onAvailableCommandsChanged(any()); - player.seekTo(/* windowIndex= */ 3, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 3, /* positionMs= */ 0); verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow); verify(mockListener, times(3)).onAvailableCommandsChanged(any()); } @@ -8534,7 +8542,7 @@ public final class ExoPlayerTest { ExoPlayer player = new TestExoPlayerBuilder(context).build(); player.addListener(mockListener); - player.seekTo(/* windowIndex= */ 3, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 3, /* positionMs= */ 0); player.addMediaSources( ImmutableList.of( new FakeMediaSource(), @@ -8545,14 +8553,14 @@ public final class ExoPlayerTest { // Check that there were no other calls to onAvailableCommandsChanged. verify(mockListener).onAvailableCommandsChanged(any()); - player.seekTo(/* windowIndex= */ 2, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 2, /* positionMs= */ 0); verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousAndNextWindow); verify(mockListener, times(2)).onAvailableCommandsChanged(any()); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ 0); verify(mockListener, times(2)).onAvailableCommandsChanged(any()); - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 0); verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToNextWindow); verify(mockListener, times(3)).onAvailableCommandsChanged(any()); } @@ -8567,8 +8575,8 @@ public final class ExoPlayerTest { player.addMediaSources(ImmutableList.of(new FakeMediaSource())); verify(mockListener).onAvailableCommandsChanged(defaultCommands); - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 200); - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 100); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 200); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 100); // Check that there were no other calls to onAvailableCommandsChanged. verify(mockListener).onAvailableCommandsChanged(any()); } @@ -8617,12 +8625,12 @@ public final class ExoPlayerTest { verify(mockListener).onAvailableCommandsChanged(commandsWithSeekInCurrentAndToNextWindow); verify(mockListener, times(2)).onAvailableCommandsChanged(any()); - playUntilStartOfWindow(player, /* windowIndex= */ 1); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 1); runUntilPendingCommandsAreFullyHandled(player); verify(mockListener).onAvailableCommandsChanged(commandsWithSeekAnywhere); verify(mockListener, times(3)).onAvailableCommandsChanged(any()); - playUntilStartOfWindow(player, /* windowIndex= */ 2); + playUntilStartOfMediaItem(player, /* mediaItemIndex= */ 2); runUntilPendingCommandsAreFullyHandled(player); verify(mockListener, times(3)).onAvailableCommandsChanged(any()); @@ -8714,7 +8722,7 @@ public final class ExoPlayerTest { ExoPlayer player = new TestExoPlayerBuilder(context).build(); player.addListener(mockListener); - player.seekTo(/* windowIndex= */ 2, /* positionMs= */ 0); + player.seekTo(/* mediaItemIndex= */ 2, /* positionMs= */ 0); player.addMediaSources( ImmutableList.of(new FakeMediaSource(), new FakeMediaSource(), new FakeMediaSource())); verify(mockListener).onAvailableCommandsChanged(commandsWithSeekToPreviousWindow); @@ -8838,7 +8846,7 @@ public final class ExoPlayerTest { .getPeriod(/* periodIndex= */ 1, new Timeline.Period(), /* setIds= */ true) .uid; assertThat(error.mediaPeriodId.periodUid).isEqualTo(period1Uid); - assertThat(player.getCurrentWindowIndex()).isEqualTo(1); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1); } @Test @@ -8884,7 +8892,7 @@ public final class ExoPlayerTest { .getPeriod(/* periodIndex= */ 1, new Timeline.Period(), /* setIds= */ true) .uid; assertThat(error.mediaPeriodId.periodUid).isEqualTo(period1Uid); - assertThat(player.getCurrentWindowIndex()).isEqualTo(1); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1); } @Test @@ -8947,7 +8955,7 @@ public final class ExoPlayerTest { .getPeriod(/* periodIndex= */ 1, new Timeline.Period(), /* setIds= */ true) .uid; assertThat(error.mediaPeriodId.periodUid).isEqualTo(period1Uid); - assertThat(player.getCurrentWindowIndex()).isEqualTo(1); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1); } @Test @@ -8988,7 +8996,7 @@ public final class ExoPlayerTest { .uid; assertThat(error.mediaPeriodId.periodUid).isEqualTo(period1Uid); // Verify test setup by checking that playing period was indeed different. - assertThat(player.getCurrentWindowIndex()).isEqualTo(0); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(0); } @Test @@ -9127,7 +9135,8 @@ public final class ExoPlayerTest { assertThat(liveOffsetAtStart).isIn(Range.closed(11_900L, 12_100L)); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 0, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9173,7 +9182,8 @@ public final class ExoPlayerTest { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY); long liveOffsetAtStart = player.getCurrentLiveOffset(); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 0, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9221,7 +9231,8 @@ public final class ExoPlayerTest { // Seek to a live offset of 2 seconds. player.seekTo(18_000); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 0, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9285,11 +9296,13 @@ public final class ExoPlayerTest { assertThat(liveOffsetAtStart).isIn(Range.closed(11_900L, 12_100L)); // Play a bit and update configuration. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 55_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 0, /* positionMs= */ 55_000); fakeMediaSource.setNewSourceInfo(updatedTimeline); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 0, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9351,7 +9364,8 @@ public final class ExoPlayerTest { player.setPlaybackParameters(new PlaybackParameters(/* speed */ 2.0f)); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 0, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9399,7 +9413,8 @@ public final class ExoPlayerTest { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 1, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 1, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9463,9 +9478,10 @@ public final class ExoPlayerTest { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY); // Seek to default position in second stream. - player.seekToNextWindow(); + player.seekToNextMediaItem(); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 1, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 1, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9529,9 +9545,10 @@ public final class ExoPlayerTest { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY); // Seek to specific position in second stream (at 2 seconds live offset). - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ 18_000); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ 18_000); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 1, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 1, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9572,7 +9589,8 @@ public final class ExoPlayerTest { TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY); long playbackStartTimeMs = fakeClock.elapsedRealtime(); - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 0, /* positionMs= */ 999_000); long playbackEndTimeMs = fakeClock.elapsedRealtime(); player.release(); @@ -9613,7 +9631,8 @@ public final class ExoPlayerTest { assertThat(liveOffsetAtStart).isIn(Range.closed(11_900L, 12_100L)); // Play until close to the end of the available live window. - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 999_000); + TestPlayerRunHelper.playUntilPosition( + player, /* mediaItemIndex= */ 0, /* positionMs= */ 999_000); long liveOffsetAtEnd = player.getCurrentLiveOffset(); player.release(); @@ -9751,7 +9770,7 @@ public final class ExoPlayerTest { TestPlayerRunHelper.runUntilPositionDiscontinuity( player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION); player.addMediaSource(secondMediaSource); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ C.TIME_UNSET); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ C.TIME_UNSET); player.play(); TestPlayerRunHelper.runUntilPositionDiscontinuity( player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION); @@ -9828,7 +9847,7 @@ public final class ExoPlayerTest { inOrder .verify(listener) .onMediaItemTransition(any(), eq(Player.MEDIA_ITEM_TRANSITION_REASON_AUTO)); - // Last auto transition from window 0 to window 1 not caused by repeat mode. + // Last auto transition from media item 0 to media item 1 not caused by repeat mode. inOrder .verify(listener) .onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION)); @@ -10004,7 +10023,7 @@ public final class ExoPlayerTest { player.setMediaSource(new FakeMediaSource(new FakeTimeline(adTimeline))); player.prepare(); - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 1000); + TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */ 0, /* positionMs= */ 1000); player.seekTo(/* positionMs= */ 8_000); player.play(); TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED); @@ -10128,7 +10147,7 @@ public final class ExoPlayerTest { ArgumentCaptor.forClass(Player.PositionInfo.class); Window window = new Window(); InOrder inOrder = Mockito.inOrder(listener); - // from first to second window + // from first to second media item inOrder .verify(listener) .onPositionDiscontinuity( @@ -10154,7 +10173,7 @@ public final class ExoPlayerTest { assertThat(newPosition.getValue().contentPositionMs).isEqualTo(0); assertThat(newPosition.getValue().adGroupIndex).isEqualTo(-1); assertThat(newPosition.getValue().adIndexInAdGroup).isEqualTo(-1); - // from second window to third + // from second media item to third inOrder .verify(listener) .onPositionDiscontinuity( @@ -10180,7 +10199,7 @@ public final class ExoPlayerTest { assertThat(newPosition.getValue().contentPositionMs).isEqualTo(0); assertThat(newPosition.getValue().adGroupIndex).isEqualTo(-1); assertThat(newPosition.getValue().adIndexInAdGroup).isEqualTo(-1); - // from third window content to post roll ad + // from third media item content to post roll ad @Nullable Object lastNewWindowUid = newPosition.getValue().windowUid; inOrder .verify(listener) @@ -10201,7 +10220,7 @@ public final class ExoPlayerTest { assertThat(newPosition.getValue().contentPositionMs).isEqualTo(20_000); assertThat(newPosition.getValue().adGroupIndex).isEqualTo(0); assertThat(newPosition.getValue().adIndexInAdGroup).isEqualTo(0); - // from third window post roll to third window content end + // from third media item post roll to third media item content end lastNewWindowUid = newPosition.getValue().windowUid; inOrder .verify(listener) @@ -10223,7 +10242,7 @@ public final class ExoPlayerTest { assertThat(newPosition.getValue().contentPositionMs).isEqualTo(19_999); assertThat(newPosition.getValue().adGroupIndex).isEqualTo(-1); assertThat(newPosition.getValue().adIndexInAdGroup).isEqualTo(-1); - // from third window content end to fourth window pre roll ad + // from third media item content end to fourth media item pre roll ad lastNewWindowUid = newPosition.getValue().windowUid; inOrder .verify(listener) @@ -10248,7 +10267,7 @@ public final class ExoPlayerTest { assertThat(newPosition.getValue().contentPositionMs).isEqualTo(0); assertThat(newPosition.getValue().adGroupIndex).isEqualTo(0); assertThat(newPosition.getValue().adIndexInAdGroup).isEqualTo(0); - // from fourth window pre roll ad to fourth window content + // from fourth media item pre roll ad to fourth media item content lastNewWindowUid = newPosition.getValue().windowUid; inOrder .verify(listener) @@ -10306,7 +10325,7 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); player.setMediaSources(ImmutableList.of(secondMediaSource, secondMediaSource)); player.play(); TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED); @@ -10428,11 +10447,11 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 1, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 1, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); player.removeMediaItem(/* index= */ 1); player.seekTo(/* positionMs= */ 0); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 0, /* positionMs= */ 2 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 0, /* positionMs= */ 2 * C.MILLIS_PER_SECOND); // Removing the last item resets the position to 0 with an empty timeline. player.removeMediaItem(0); TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED); @@ -10517,7 +10536,7 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 1, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 1, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); concatenatingMediaSource.removeMediaSource(1); TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(player); concatenatingMediaSource.removeMediaSource(1); @@ -10590,9 +10609,9 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 1, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 1, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); concatenatingMediaSource.removeMediaSource(1); - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 1234); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 1234); TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(player); concatenatingMediaSource.removeMediaSource(0); player.play(); @@ -10708,9 +10727,9 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); player.seekTo(/* positionMs= */ 7 * C.MILLIS_PER_SECOND); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ C.MILLIS_PER_SECOND); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ C.MILLIS_PER_SECOND); player.play(); TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED); @@ -10753,7 +10772,7 @@ public final class ExoPlayerTest { player.addListener(listener); player.seekTo(/* positionMs= */ 7 * C.MILLIS_PER_SECOND); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ C.MILLIS_PER_SECOND); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ C.MILLIS_PER_SECOND); player.seekTo(/* positionMs= */ 5 * C.MILLIS_PER_SECOND); ArgumentCaptor oldPosition = @@ -10787,7 +10806,7 @@ public final class ExoPlayerTest { assertThat(newPositions.get(1).mediaItemIndex).isEqualTo(1); assertThat(newPositions.get(1).positionMs).isEqualTo(1_000); assertThat(newPositions.get(1).contentPositionMs).isEqualTo(1_000); - // a seek from masked seek position to another masked position within window + // a seek from masked seek position to another masked position within media item assertThat(oldPositions.get(2).windowUid).isNull(); assertThat(oldPositions.get(2).mediaItemIndex).isEqualTo(1); assertThat(oldPositions.get(2).mediaItem).isNull(); @@ -10815,7 +10834,7 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 0, /* positionMs= */ 2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS); + player, /* mediaItemIndex= */ 0, /* positionMs= */ 2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS); player.seekBack(); ArgumentCaptor oldPosition = @@ -10862,7 +10881,7 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 0, /* positionMs= */ C.DEFAULT_SEEK_BACK_INCREMENT_MS / 2); + player, /* mediaItemIndex= */ 0, /* positionMs= */ C.DEFAULT_SEEK_BACK_INCREMENT_MS / 2); player.seekBack(); assertThat(player.getCurrentPosition()).isEqualTo(0); @@ -10933,11 +10952,11 @@ public final class ExoPlayerTest { public void seekToPrevious_withPreviousWindowAndCloseToStart_seeksToPreviousWindow() { ExoPlayer player = new TestExoPlayerBuilder(context).build(); player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource())); - player.seekTo(/* windowIndex= */ 1, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS); + player.seekTo(/* mediaItemIndex= */ 1, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS); player.seekToPrevious(); - assertThat(player.getCurrentWindowIndex()).isEqualTo(0); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(0); assertThat(player.getCurrentPosition()).isEqualTo(0); player.release(); @@ -10947,11 +10966,11 @@ public final class ExoPlayerTest { public void seekToPrevious_notCloseToStart_seeksToZero() { ExoPlayer player = new TestExoPlayerBuilder(context).build(); player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource())); - player.seekTo(/* windowIndex= */ 1, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS + 1); + player.seekTo(/* mediaItemIndex= */ 1, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS + 1); player.seekToPrevious(); - assertThat(player.getCurrentWindowIndex()).isEqualTo(1); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1); assertThat(player.getCurrentPosition()).isEqualTo(0); player.release(); @@ -10964,7 +10983,7 @@ public final class ExoPlayerTest { player.seekToNext(); - assertThat(player.getCurrentWindowIndex()).isEqualTo(1); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(1); assertThat(player.getCurrentPosition()).isEqualTo(0); player.release(); @@ -10994,7 +11013,7 @@ public final class ExoPlayerTest { player.seekTo(/* positionMs = */ 0); player.seekToNext(); - assertThat(player.getCurrentWindowIndex()).isEqualTo(0); + assertThat(player.getCurrentMediaItemIndex()).isEqualTo(0); assertThat(player.getCurrentPosition()).isEqualTo(500); player.release(); @@ -11009,7 +11028,7 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); player.stop(); verify(listener, never()).onPositionDiscontinuity(any(), any(), anyInt()); @@ -11027,7 +11046,7 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); player.stop(/* reset= */ true); ArgumentCaptor oldPosition = @@ -11071,13 +11090,13 @@ public final class ExoPlayerTest { player.setMediaSource(mediaSource); player.prepare(); - TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */ 1, /* positionMs= */ 2000); - player.seekTo(/* windowIndex= */ 1, /* positionMs= */ 2122); + TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */ 1, /* positionMs= */ 2000); + player.seekTo(/* mediaItemIndex= */ 1, /* positionMs= */ 2122); // This causes a DISCONTINUITY_REASON_REMOVE between pending operations that needs to be // cancelled by the seek below. mediaSource.setNewSourceInfo(timeline2); player.play(); - player.seekTo(/* windowIndex= */ 0, /* positionMs= */ 2222); + player.seekTo(/* mediaItemIndex= */ 0, /* positionMs= */ 2222); TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED); ArgumentCaptor oldPosition = @@ -11176,7 +11195,7 @@ public final class ExoPlayerTest { .send(); player.setMediaSource(mediaSource); player.prepare(); - playUntilPosition(player, /* windowIndex= */ 0, /* positionMs= */ 40_000); + playUntilPosition(player, /* mediaItemIndex= */ 0, /* positionMs= */ 40_000); player.release(); // Assert that the renderer hasn't been reset despite the inserted ad group. @@ -11215,7 +11234,7 @@ public final class ExoPlayerTest { player.prepare(); TestPlayerRunHelper.playUntilPosition( - player, /* windowIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); + player, /* mediaItemIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND); player.stop(); shadowOf(Looper.getMainLooper()).idle(); @@ -11360,18 +11379,18 @@ public final class ExoPlayerTest { private static final class PositionGrabbingMessageTarget extends PlayerTarget { - public int windowIndex; + public int mediaItemIndex; public long positionMs; public int messageCount; public PositionGrabbingMessageTarget() { - windowIndex = C.INDEX_UNSET; + mediaItemIndex = C.INDEX_UNSET; positionMs = C.POSITION_UNSET; } @Override public void handleMessage(ExoPlayer player, int messageType, @Nullable Object message) { - windowIndex = player.getCurrentWindowIndex(); + mediaItemIndex = player.getCurrentMediaItemIndex(); positionMs = player.getCurrentPosition(); messageCount++; } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java index 6adfe54b4f..a7838377bf 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java @@ -950,7 +950,7 @@ public class PlayerControlView extends FrameLayout { int adGroupCount = 0; Timeline timeline = player.getCurrentTimeline(); if (!timeline.isEmpty()) { - int currentWindowIndex = player.getCurrentWindowIndex(); + int currentWindowIndex = player.getCurrentMediaItemIndex(); int firstWindowIndex = multiWindowTimeBar ? 0 : currentWindowIndex; int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex; for (int i = firstWindowIndex; i <= lastWindowIndex; i++) { @@ -1110,7 +1110,7 @@ public class PlayerControlView extends FrameLayout { windowIndex++; } } else { - windowIndex = player.getCurrentWindowIndex(); + windowIndex = player.getCurrentMediaItemIndex(); } seekTo(player, windowIndex, positionMs); updateProgress(); @@ -1228,7 +1228,7 @@ public class PlayerControlView extends FrameLayout { if (state == Player.STATE_IDLE) { player.prepare(); } else if (state == Player.STATE_ENDED) { - seekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); + seekTo(player, player.getCurrentMediaItemIndex(), C.TIME_UNSET); } player.play(); } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java index 26075126d0..682483cd4e 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java @@ -605,9 +605,9 @@ public class PlayerNotificationManager { public static final String ACTION_PLAY = "com.google.android.exoplayer.play"; /** The action which pauses playback. */ public static final String ACTION_PAUSE = "com.google.android.exoplayer.pause"; - /** The action which skips to the previous window. */ + /** The action which skips to the previous media item. */ public static final String ACTION_PREVIOUS = "com.google.android.exoplayer.prev"; - /** The action which skips to the next window. */ + /** The action which skips to the next media item. */ public static final String ACTION_NEXT = "com.google.android.exoplayer.next"; /** The action which fast forwards. */ public static final String ACTION_FAST_FORWARD = "com.google.android.exoplayer.ffwd"; @@ -1095,7 +1095,7 @@ public class PlayerNotificationManager { * *
      *
    • The media is {@link Player#isPlaying() actively playing}. - *
    • The media is not {@link Player#isCurrentWindowDynamic() dynamically changing its + *
    • The media is not {@link Player#isCurrentMediaItemDynamic() dynamically changing its * duration} (like for example a live stream). *
    • The media is not {@link Player#isPlayingAd() interrupted by an ad}. *
    • The media is played at {@link Player#getPlaybackParameters() regular speed}. @@ -1253,7 +1253,7 @@ public class PlayerNotificationManager { && useChronometer && player.isPlaying() && !player.isPlayingAd() - && !player.isCurrentWindowDynamic() + && !player.isCurrentMediaItemDynamic() && player.getPlaybackParameters().speed == 1f) { builder .setWhen(System.currentTimeMillis() - player.getContentPosition()) @@ -1531,7 +1531,7 @@ public class PlayerNotificationManager { if (player.getPlaybackState() == Player.STATE_IDLE) { player.prepare(); } else if (player.getPlaybackState() == Player.STATE_ENDED) { - player.seekToDefaultPosition(player.getCurrentWindowIndex()); + player.seekToDefaultPosition(player.getCurrentMediaItemIndex()); } player.play(); } else if (ACTION_PAUSE.equals(action)) { 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 4836774bb2..30533dcd19 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 @@ -1501,8 +1501,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider { if (lastPeriodIndexWithTracks != C.INDEX_UNSET) { int lastWindowIndexWithTracks = timeline.getPeriod(lastPeriodIndexWithTracks, period).windowIndex; - if (player.getCurrentWindowIndex() == lastWindowIndexWithTracks) { - // We're in the same window. Suppress the update. + if (player.getCurrentMediaItemIndex() == lastWindowIndexWithTracks) { + // We're in the same media item. Suppress the update. return; } } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java index 279e907476..c6e0aadad0 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerControlView.java @@ -1269,7 +1269,7 @@ public class StyledPlayerControlView extends FrameLayout { int adGroupCount = 0; Timeline timeline = player.getCurrentTimeline(); if (!timeline.isEmpty()) { - int currentWindowIndex = player.getCurrentWindowIndex(); + int currentWindowIndex = player.getCurrentMediaItemIndex(); int firstWindowIndex = multiWindowTimeBar ? 0 : currentWindowIndex; int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex; for (int i = firstWindowIndex; i <= lastWindowIndex; i++) { @@ -1453,7 +1453,7 @@ public class StyledPlayerControlView extends FrameLayout { windowIndex++; } } else { - windowIndex = player.getCurrentWindowIndex(); + windowIndex = player.getCurrentMediaItemIndex(); } seekTo(player, windowIndex, positionMs); updateProgress(); @@ -1616,13 +1616,12 @@ public class StyledPlayerControlView extends FrameLayout { } } - @SuppressWarnings("deprecation") private void dispatchPlay(Player player) { @State int state = player.getPlaybackState(); if (state == Player.STATE_IDLE) { player.prepare(); } else if (state == Player.STATE_ENDED) { - seekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); + seekTo(player, player.getCurrentMediaItemIndex(), C.TIME_UNSET); } player.play(); } 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 4434aef516..b8907094fd 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 @@ -1540,8 +1540,8 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider { if (lastPeriodIndexWithTracks != C.INDEX_UNSET) { int lastWindowIndexWithTracks = timeline.getPeriod(lastPeriodIndexWithTracks, period).windowIndex; - if (player.getCurrentWindowIndex() == lastWindowIndexWithTracks) { - // We're in the same window. Suppress the update. + if (player.getCurrentMediaItemIndex() == lastWindowIndexWithTracks) { + // We're in the same media item. Suppress the update. return; } } 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 efcb290579..58ed22f289 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 @@ -284,12 +284,12 @@ public class TestPlayerRunHelper { *

      If a playback error occurs it will be thrown wrapped in an {@link IllegalStateException}. * * @param player The {@link Player}. - * @param windowIndex The window. - * @param positionMs The position within the window, in milliseconds. + * @param mediaItemIndex The index of the media item. + * @param positionMs The position within the media item, in milliseconds. * @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is * exceeded. */ - public static void playUntilPosition(ExoPlayer player, int windowIndex, long positionMs) + public static void playUntilPosition(ExoPlayer player, int mediaItemIndex, long positionMs) throws TimeoutException { verifyMainTestThread(player); Looper applicationLooper = Util.getCurrentOrMainLooper(); @@ -315,7 +315,7 @@ public class TestPlayerRunHelper { // Ignore. } }) - .setPosition(windowIndex, positionMs) + .setPosition(mediaItemIndex, positionMs) .send(); player.play(); runMainLooperUntil(() -> messageHandled.get() || player.getPlayerError() != null); @@ -326,18 +326,19 @@ public class TestPlayerRunHelper { /** * Calls {@link Player#play()}, runs tasks of the main {@link Looper} until the {@code player} - * reaches the specified window or a playback error occurs, and then pauses the {@code player}. + * reaches the specified media item or a playback error occurs, and then pauses the {@code + * player}. * *

      If a playback error occurs it will be thrown wrapped in an {@link IllegalStateException}. * * @param player The {@link Player}. - * @param windowIndex The window. + * @param mediaItemIndex The index of the media item. * @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is * exceeded. */ - public static void playUntilStartOfWindow(ExoPlayer player, int windowIndex) + public static void playUntilStartOfMediaItem(ExoPlayer player, int mediaItemIndex) throws TimeoutException { - playUntilPosition(player, windowIndex, /* positionMs= */ 0); + playUntilPosition(player, mediaItemIndex, /* positionMs= */ 0); } /** diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java index 43d5162bd3..b5cdf77d5c 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java @@ -121,7 +121,7 @@ public abstract class Action { /** Calls {@link Player#seekTo(long)} or {@link Player#seekTo(int, long)}. */ public static final class Seek extends Action { - @Nullable private final Integer windowIndex; + @Nullable private final Integer mediaItemIndex; private final long positionMs; private final boolean catchIllegalSeekException; @@ -133,7 +133,7 @@ public abstract class Action { */ public Seek(String tag, long positionMs) { super(tag, "Seek:" + positionMs); - this.windowIndex = null; + this.mediaItemIndex = null; this.positionMs = positionMs; catchIllegalSeekException = false; } @@ -142,14 +142,15 @@ public abstract class Action { * Action calls {@link Player#seekTo(int, long)}. * * @param tag A tag to use for logging. - * @param windowIndex The window to seek to. + * @param mediaItemIndex The media item to seek to. * @param positionMs The seek position. * @param catchIllegalSeekException Whether {@link IllegalSeekPositionException} should be * silently caught or not. */ - public Seek(String tag, int windowIndex, long positionMs, boolean catchIllegalSeekException) { + public Seek( + String tag, int mediaItemIndex, long positionMs, boolean catchIllegalSeekException) { super(tag, "Seek:" + positionMs); - this.windowIndex = windowIndex; + this.mediaItemIndex = mediaItemIndex; this.positionMs = positionMs; this.catchIllegalSeekException = catchIllegalSeekException; } @@ -158,10 +159,10 @@ public abstract class Action { protected void doActionImpl( ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) { try { - if (windowIndex == null) { + if (mediaItemIndex == null) { player.seekTo(positionMs); } else { - player.seekTo(windowIndex, positionMs); + player.seekTo(mediaItemIndex, positionMs); } } catch (IllegalSeekPositionException e) { if (!catchIllegalSeekException) { @@ -174,20 +175,20 @@ public abstract class Action { /** Calls {@link ExoPlayer#setMediaSources(List, int, long)}. */ public static final class SetMediaItems extends Action { - private final int windowIndex; + private final int mediaItemIndex; private final long positionMs; private final MediaSource[] mediaSources; /** * @param tag A tag to use for logging. - * @param windowIndex The window index to start playback from. + * @param mediaItemIndex The media item index to start playback from. * @param positionMs The position in milliseconds to start playback from. * @param mediaSources The media sources to populate the playlist with. */ public SetMediaItems( - String tag, int windowIndex, long positionMs, MediaSource... mediaSources) { + String tag, int mediaItemIndex, long positionMs, MediaSource... mediaSources) { super(tag, "SetMediaItems"); - this.windowIndex = windowIndex; + this.mediaItemIndex = mediaItemIndex; this.positionMs = positionMs; this.mediaSources = mediaSources; } @@ -195,7 +196,7 @@ public abstract class Action { @Override protected void doActionImpl( ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) { - player.setMediaSources(Arrays.asList(mediaSources), windowIndex, positionMs); + player.setMediaSources(Arrays.asList(mediaSources), mediaItemIndex, positionMs); } } @@ -553,7 +554,7 @@ public abstract class Action { public static final class SendMessages extends Action { private final Target target; - private final int windowIndex; + private final int mediaItemIndex; private final long positionMs; private final boolean deleteAfterDelivery; @@ -566,7 +567,7 @@ public abstract class Action { this( tag, target, - /* windowIndex= */ C.INDEX_UNSET, + /* mediaItemIndex= */ C.INDEX_UNSET, positionMs, /* deleteAfterDelivery= */ true); } @@ -574,16 +575,20 @@ public abstract class Action { /** * @param tag A tag to use for logging. * @param target A message target. - * @param windowIndex The window index at which the message should be sent, or {@link - * C#INDEX_UNSET} for the current window. + * @param mediaItemIndex The media item index at which the message should be sent, or {@link + * C#INDEX_UNSET} for the current media item. * @param positionMs The position at which the message should be sent, in milliseconds. * @param deleteAfterDelivery Whether the message will be deleted after delivery. */ public SendMessages( - String tag, Target target, int windowIndex, long positionMs, boolean deleteAfterDelivery) { + String tag, + Target target, + int mediaItemIndex, + long positionMs, + boolean deleteAfterDelivery) { super(tag, "SendMessages"); this.target = target; - this.windowIndex = windowIndex; + this.mediaItemIndex = mediaItemIndex; this.positionMs = positionMs; this.deleteAfterDelivery = deleteAfterDelivery; } @@ -595,8 +600,8 @@ public abstract class Action { ((PlayerTarget) target).setPlayer(player); } PlayerMessage message = player.createMessage(target); - if (windowIndex != C.INDEX_UNSET) { - message.setPosition(windowIndex, positionMs); + if (mediaItemIndex != C.INDEX_UNSET) { + message.setPosition(mediaItemIndex, positionMs); } else { message.setPosition(positionMs); } @@ -661,17 +666,17 @@ public abstract class Action { */ public static final class PlayUntilPosition extends Action { - private final int windowIndex; + private final int mediaItemIndex; private final long positionMs; /** * @param tag A tag to use for logging. - * @param windowIndex The window index at which the player should be paused again. - * @param positionMs The position in that window at which the player should be paused again. + * @param mediaItemIndex The media item index at which the player should be paused again. + * @param positionMs The position in that media item at which the player should be paused again. */ - public PlayUntilPosition(String tag, int windowIndex, long positionMs) { - super(tag, "PlayUntilPosition:" + windowIndex + ":" + positionMs); - this.windowIndex = windowIndex; + public PlayUntilPosition(String tag, int mediaItemIndex, long positionMs) { + super(tag, "PlayUntilPosition:" + mediaItemIndex + ":" + positionMs); + this.mediaItemIndex = mediaItemIndex; this.positionMs = positionMs; } @@ -704,7 +709,7 @@ public abstract class Action { // Ignore. } }) - .setPosition(windowIndex, positionMs) + .setPosition(mediaItemIndex, positionMs) .send(); if (nextAction != null) { // Schedule another message on this test thread to continue action schedule. @@ -712,7 +717,7 @@ public abstract class Action { .createMessage( (messageType, payload) -> nextAction.schedule(player, trackSelector, surface, handler)) - .setPosition(windowIndex, positionMs) + .setPosition(mediaItemIndex, positionMs) .setLooper(applicationLooper) .send(); } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java index 4590d5fd6b..0282e57a8c 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java @@ -161,24 +161,25 @@ public final class ActionSchedule { /** * Schedules a seek action. * - * @param windowIndex The window to seek to. + * @param mediaItemIndex The media item to seek to. * @param positionMs The seek position. * @return The builder, for convenience. */ - public Builder seek(int windowIndex, long positionMs) { - return apply(new Seek(tag, windowIndex, positionMs, /* catchIllegalSeekException= */ false)); + public Builder seek(int mediaItemIndex, long positionMs) { + return apply( + new Seek(tag, mediaItemIndex, positionMs, /* catchIllegalSeekException= */ false)); } /** * Schedules a seek action to be executed. * - * @param windowIndex The window to seek to. + * @param mediaItemIndex The media item to seek to. * @param positionMs The seek position. * @param catchIllegalSeekException Whether an illegal seek position should be caught or not. * @return The builder, for convenience. */ - public Builder seek(int windowIndex, long positionMs, boolean catchIllegalSeekException) { - return apply(new Seek(tag, windowIndex, positionMs, catchIllegalSeekException)); + public Builder seek(int mediaItemIndex, long positionMs, boolean catchIllegalSeekException) { + return apply(new Seek(tag, mediaItemIndex, positionMs, catchIllegalSeekException)); } /** @@ -247,23 +248,23 @@ public final class ActionSchedule { * Schedules a play action, waits until the player reaches the specified position, and pauses * the player again. * - * @param windowIndex The window index at which the player should be paused again. - * @param positionMs The position in that window at which the player should be paused again. + * @param mediaItemIndex The media item index at which the player should be paused again. + * @param positionMs The position in that media item at which the player should be paused again. * @return The builder, for convenience. */ - public Builder playUntilPosition(int windowIndex, long positionMs) { - return apply(new PlayUntilPosition(tag, windowIndex, positionMs)); + public Builder playUntilPosition(int mediaItemIndex, long positionMs) { + return apply(new PlayUntilPosition(tag, mediaItemIndex, positionMs)); } /** - * Schedules a play action, waits until the player reaches the start of the specified window, - * and pauses the player again. + * Schedules a play action, waits until the player reaches the start of the specified media + * item, and pauses the player again. * - * @param windowIndex The window index at which the player should be paused again. + * @param mediaItemIndex The media item index at which the player should be paused again. * @return The builder, for convenience. */ - public Builder playUntilStartOfWindow(int windowIndex) { - return apply(new PlayUntilPosition(tag, windowIndex, /* positionMs= */ 0)); + public Builder playUntilStartOfMediaItem(int mediaItemIndex) { + return apply(new PlayUntilPosition(tag, mediaItemIndex, /* positionMs= */ 0)); } /** @@ -323,16 +324,16 @@ public final class ActionSchedule { /** * Schedules a set media items action to be executed. * - * @param windowIndex The window index to start playback from or {@link C#INDEX_UNSET} if the - * playback position should not be reset. + * @param mediaItemIndex The media item index to start playback from or {@link C#INDEX_UNSET} if + * the playback position should not be reset. * @param positionMs The position in milliseconds from where playback should start. If {@link - * C#TIME_UNSET} is passed the default position is used. In any case, if {@code windowIndex} - * is set to {@link C#INDEX_UNSET} the position is not reset at all and this parameter is - * ignored. + * C#TIME_UNSET} is passed the default position is used. In any case, if {@code + * mediaItemIndex} is set to {@link C#INDEX_UNSET} the position is not reset at all and this + * parameter is ignored. * @return The builder, for convenience. */ - public Builder setMediaSources(int windowIndex, long positionMs, MediaSource... sources) { - return apply(new Action.SetMediaItems(tag, windowIndex, positionMs, sources)); + public Builder setMediaSources(int mediaItemIndex, long positionMs, MediaSource... sources) { + return apply(new Action.SetMediaItems(tag, mediaItemIndex, positionMs, sources)); } /** @@ -354,7 +355,10 @@ public final class ActionSchedule { public Builder setMediaSources(MediaSource... mediaSources) { return apply( new Action.SetMediaItems( - tag, /* windowIndex= */ C.INDEX_UNSET, /* positionMs= */ C.TIME_UNSET, mediaSources)); + tag, + /* mediaItemIndex= */ C.INDEX_UNSET, + /* positionMs= */ C.TIME_UNSET, + mediaSources)); } /** * Schedules a add media items action to be executed. @@ -447,8 +451,8 @@ public final class ActionSchedule { /** * Schedules sending a {@link PlayerMessage}. * - * @param positionMs The position in the current window at which the message should be sent, in - * milliseconds. + * @param positionMs The position in the current media item at which the message should be sent, + * in milliseconds. * @return The builder, for convenience. */ public Builder sendMessage(Target target, long positionMs) { @@ -459,27 +463,28 @@ public final class ActionSchedule { * Schedules sending a {@link PlayerMessage}. * * @param target A message target. - * @param windowIndex The window index at which the message should be sent. + * @param mediaItemIndex The media item index at which the message should be sent. * @param positionMs The position at which the message should be sent, in milliseconds. * @return The builder, for convenience. */ - public Builder sendMessage(Target target, int windowIndex, long positionMs) { + public Builder sendMessage(Target target, int mediaItemIndex, long positionMs) { return apply( - new SendMessages(tag, target, windowIndex, positionMs, /* deleteAfterDelivery= */ true)); + new SendMessages( + tag, target, mediaItemIndex, positionMs, /* deleteAfterDelivery= */ true)); } /** * Schedules to send a {@link PlayerMessage}. * * @param target A message target. - * @param windowIndex The window index at which the message should be sent. + * @param mediaItemIndex The media item index at which the message should be sent. * @param positionMs The position at which the message should be sent, in milliseconds. * @param deleteAfterDelivery Whether the message will be deleted after delivery. * @return The builder, for convenience. */ public Builder sendMessage( - Target target, int windowIndex, long positionMs, boolean deleteAfterDelivery) { - return apply(new SendMessages(tag, target, windowIndex, positionMs, deleteAfterDelivery)); + Target target, int mediaItemIndex, long positionMs, boolean deleteAfterDelivery) { + return apply(new SendMessages(tag, target, mediaItemIndex, positionMs, deleteAfterDelivery)); } /** diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ExoPlayerTestRunner.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ExoPlayerTestRunner.java index 6df171442d..1a305f0e35 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ExoPlayerTestRunner.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ExoPlayerTestRunner.java @@ -85,7 +85,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul private AnalyticsListener analyticsListener; private Integer expectedPlayerEndedCount; private boolean pauseAtEndOfMediaItems; - private int initialWindowIndex; + private int initialMediaItemIndex; private long initialPositionMs; private boolean skipSettingMediaSources; @@ -93,7 +93,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul testPlayerBuilder = new TestExoPlayerBuilder(context); mediaSources = new ArrayList<>(); supportedFormats = new Format[] {VIDEO_FORMAT}; - initialWindowIndex = C.INDEX_UNSET; + initialMediaItemIndex = C.INDEX_UNSET; initialPositionMs = C.TIME_UNSET; } @@ -133,12 +133,12 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul /** * Seeks before setting the media sources and preparing the player. * - * @param windowIndex The window index to seek to. + * @param mediaItemIndex The media item index to seek to. * @param positionMs The position in milliseconds to seek to. * @return This builder. */ - public Builder initialSeek(int windowIndex, long positionMs) { - this.initialWindowIndex = windowIndex; + public Builder initialSeek(int mediaItemIndex, long positionMs) { + this.initialMediaItemIndex = mediaItemIndex; this.initialPositionMs = positionMs; return this; } @@ -343,7 +343,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul testPlayerBuilder, mediaSources, skipSettingMediaSources, - initialWindowIndex, + initialMediaItemIndex, initialPositionMs, surface, actionSchedule, @@ -357,7 +357,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul private final TestExoPlayerBuilder playerBuilder; private final List mediaSources; private final boolean skipSettingMediaSources; - private final int initialWindowIndex; + private final int initialMediaItemIndex; private final long initialPositionMs; @Nullable private final Surface surface; @Nullable private final ActionSchedule actionSchedule; @@ -386,7 +386,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul TestExoPlayerBuilder playerBuilder, List mediaSources, boolean skipSettingMediaSources, - int initialWindowIndex, + int initialMediaItemIndex, long initialPositionMs, @Nullable Surface surface, @Nullable ActionSchedule actionSchedule, @@ -397,7 +397,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul this.playerBuilder = playerBuilder; this.mediaSources = mediaSources; this.skipSettingMediaSources = skipSettingMediaSources; - this.initialWindowIndex = initialWindowIndex; + this.initialMediaItemIndex = initialMediaItemIndex; this.initialPositionMs = initialPositionMs; this.surface = surface; this.actionSchedule = actionSchedule; @@ -466,8 +466,8 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul handler, /* callback= */ ExoPlayerTestRunner.this); } - if (initialWindowIndex != C.INDEX_UNSET) { - player.seekTo(initialWindowIndex, initialPositionMs); + if (initialMediaItemIndex != C.INDEX_UNSET) { + player.seekTo(initialMediaItemIndex, initialPositionMs); } if (!skipSettingMediaSources) { player.setMediaSources(mediaSources, /* resetPosition= */ false); 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 c0acae1da6..136327739f 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 @@ -162,7 +162,7 @@ public class StubExoPlayer extends StubPlayer implements ExoPlayer { @Override public void setMediaSources( - List mediaSources, int startWindowIndex, long startPositionMs) { + List mediaSources, int startMediaItemIndex, long startPositionMs) { throw new UnsupportedOperationException(); } From ee4af48a10084c0aca95dd2ed4b23a39187f62c0 Mon Sep 17 00:00:00 2001 From: christosts Date: Tue, 2 Nov 2021 10:49:18 +0000 Subject: [PATCH 2/3] Replace map with a switch statement in bandwidth meter implementations #minor-release PiperOrigin-RevId: 407042882 --- .../upstream/DefaultBandwidthMeter.java | 713 +++++++++++------- 1 file changed, 438 insertions(+), 275 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultBandwidthMeter.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultBandwidthMeter.java index 07b3185b43..2db19fb6a7 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultBandwidthMeter.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultBandwidthMeter.java @@ -26,10 +26,8 @@ import com.google.android.exoplayer2.util.NetworkTypeObserver; import com.google.android.exoplayer2.util.Util; import com.google.common.base.Ascii; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableMap; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -42,13 +40,6 @@ import java.util.Map; */ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferListener { - /** - * Country groups used to determine the default initial bitrate estimate. The group assignment for - * each country is a list for [Wifi, 2G, 3G, 4G, 5G_NSA, 5G_SA]. - */ - public static final ImmutableListMultimap - DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS = createInitialBitrateCountryGroupAssignment(); - /** Default initial Wifi bitrate estimate in bits per second. */ public static final ImmutableList DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI = ImmutableList.of(5_400_000L, 3_300_000L, 2_000_000L, 1_300_000L, 760_000L); @@ -82,17 +73,35 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList /** Default maximum weight for the sliding window. */ public static final int DEFAULT_SLIDING_WINDOW_MAX_WEIGHT = 2000; - /** Index for the Wifi group index in {@link #DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS}. */ + /** + * Index for the Wifi group index in the array returned by {@link + * #getInitialBitrateCountryGroupAssignment}. + */ private static final int COUNTRY_GROUP_INDEX_WIFI = 0; - /** Index for the 2G group index in {@link #DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS}. */ + /** + * Index for the 2G group index in the array returned by {@link + * #getInitialBitrateCountryGroupAssignment}. + */ private static final int COUNTRY_GROUP_INDEX_2G = 1; - /** Index for the 3G group index in {@link #DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS}. */ + /** + * Index for the 3G group index in the array returned by {@link + * #getInitialBitrateCountryGroupAssignment}. + */ private static final int COUNTRY_GROUP_INDEX_3G = 2; - /** Index for the 4G group index in {@link #DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS}. */ + /** + * Index for the 4G group index in the array returned by {@link + * #getInitialBitrateCountryGroupAssignment}. + */ private static final int COUNTRY_GROUP_INDEX_4G = 3; - /** Index for the 5G-NSA group index in {@link #DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS}. */ + /** + * Index for the 5G-NSA group index in the array returned by {@link + * #getInitialBitrateCountryGroupAssignment}. + */ private static final int COUNTRY_GROUP_INDEX_5G_NSA = 4; - /** Index for the 5G-SA group index in {@link #DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS}. */ + /** + * Index for the 5G-SA group index in the array returned by {@link + * #getInitialBitrateCountryGroupAssignment}. + */ private static final int COUNTRY_GROUP_INDEX_5G_SA = 5; @Nullable private static DefaultBandwidthMeter singletonInstance; @@ -212,40 +221,33 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList } private static Map getInitialBitrateEstimatesForCountry(String countryCode) { - List groupIndices = getCountryGroupIndices(countryCode); + int[] groupIndices = getInitialBitrateCountryGroupAssignment(countryCode); Map result = new HashMap<>(/* initialCapacity= */ 8); result.put(C.NETWORK_TYPE_UNKNOWN, DEFAULT_INITIAL_BITRATE_ESTIMATE); result.put( C.NETWORK_TYPE_WIFI, - DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices.get(COUNTRY_GROUP_INDEX_WIFI))); + DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices[COUNTRY_GROUP_INDEX_WIFI])); result.put( C.NETWORK_TYPE_2G, - DEFAULT_INITIAL_BITRATE_ESTIMATES_2G.get(groupIndices.get(COUNTRY_GROUP_INDEX_2G))); + DEFAULT_INITIAL_BITRATE_ESTIMATES_2G.get(groupIndices[COUNTRY_GROUP_INDEX_2G])); result.put( C.NETWORK_TYPE_3G, - DEFAULT_INITIAL_BITRATE_ESTIMATES_3G.get(groupIndices.get(COUNTRY_GROUP_INDEX_3G))); + DEFAULT_INITIAL_BITRATE_ESTIMATES_3G.get(groupIndices[COUNTRY_GROUP_INDEX_3G])); result.put( C.NETWORK_TYPE_4G, - DEFAULT_INITIAL_BITRATE_ESTIMATES_4G.get(groupIndices.get(COUNTRY_GROUP_INDEX_4G))); + DEFAULT_INITIAL_BITRATE_ESTIMATES_4G.get(groupIndices[COUNTRY_GROUP_INDEX_4G])); result.put( C.NETWORK_TYPE_5G_NSA, - DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA.get( - groupIndices.get(COUNTRY_GROUP_INDEX_5G_NSA))); + DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_NSA.get(groupIndices[COUNTRY_GROUP_INDEX_5G_NSA])); result.put( C.NETWORK_TYPE_5G_SA, - DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA.get(groupIndices.get(COUNTRY_GROUP_INDEX_5G_SA))); + DEFAULT_INITIAL_BITRATE_ESTIMATES_5G_SA.get(groupIndices[COUNTRY_GROUP_INDEX_5G_SA])); // Assume default Wifi speed for Ethernet to prevent using the slower fallback. result.put( C.NETWORK_TYPE_ETHERNET, - DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices.get(COUNTRY_GROUP_INDEX_WIFI))); + DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI.get(groupIndices[COUNTRY_GROUP_INDEX_WIFI])); return result; } - - private static ImmutableList getCountryGroupIndices(String countryCode) { - ImmutableList groupIndices = DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS.get(countryCode); - // Assume median group if not found. - return groupIndices.isEmpty() ? ImmutableList.of(2, 2, 2, 2, 2, 2) : groupIndices; - } } /** @@ -461,250 +463,411 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList return isNetwork && !dataSpec.isFlagSet(DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED); } - private static ImmutableListMultimap - createInitialBitrateCountryGroupAssignment() { - return ImmutableListMultimap.builder() - .putAll("AD", 1, 2, 0, 0, 2, 2) - .putAll("AE", 1, 4, 4, 4, 3, 2) - .putAll("AF", 4, 4, 4, 4, 2, 2) - .putAll("AG", 2, 3, 1, 2, 2, 2) - .putAll("AI", 1, 2, 2, 2, 2, 2) - .putAll("AL", 1, 2, 0, 1, 2, 2) - .putAll("AM", 2, 3, 2, 4, 2, 2) - .putAll("AO", 3, 4, 3, 2, 2, 2) - .putAll("AQ", 4, 2, 2, 2, 2, 2) - .putAll("AR", 2, 4, 1, 1, 2, 2) - .putAll("AS", 2, 2, 2, 3, 2, 2) - .putAll("AT", 0, 0, 0, 0, 0, 2) - .putAll("AU", 0, 1, 0, 1, 2, 2) - .putAll("AW", 1, 2, 4, 4, 2, 2) - .putAll("AX", 0, 2, 2, 2, 2, 2) - .putAll("AZ", 3, 2, 4, 4, 2, 2) - .putAll("BA", 1, 2, 0, 1, 2, 2) - .putAll("BB", 0, 2, 0, 0, 2, 2) - .putAll("BD", 2, 1, 3, 3, 2, 2) - .putAll("BE", 0, 0, 3, 3, 2, 2) - .putAll("BF", 4, 3, 4, 3, 2, 2) - .putAll("BG", 0, 0, 0, 0, 1, 2) - .putAll("BH", 1, 2, 2, 4, 4, 2) - .putAll("BI", 4, 3, 4, 4, 2, 2) - .putAll("BJ", 4, 4, 3, 4, 2, 2) - .putAll("BL", 1, 2, 2, 2, 2, 2) - .putAll("BM", 1, 2, 0, 0, 2, 2) - .putAll("BN", 3, 2, 1, 1, 2, 2) - .putAll("BO", 1, 3, 3, 2, 2, 2) - .putAll("BQ", 1, 2, 2, 0, 2, 2) - .putAll("BR", 2, 3, 2, 2, 2, 2) - .putAll("BS", 4, 2, 2, 3, 2, 2) - .putAll("BT", 3, 1, 3, 2, 2, 2) - .putAll("BW", 3, 4, 1, 0, 2, 2) - .putAll("BY", 0, 1, 1, 3, 2, 2) - .putAll("BZ", 2, 4, 2, 2, 2, 2) - .putAll("CA", 0, 2, 1, 2, 4, 1) - .putAll("CD", 4, 2, 3, 1, 2, 2) - .putAll("CF", 4, 2, 3, 2, 2, 2) - .putAll("CG", 2, 4, 3, 4, 2, 2) - .putAll("CH", 0, 0, 0, 0, 0, 2) - .putAll("CI", 3, 3, 3, 4, 2, 2) - .putAll("CK", 2, 2, 2, 1, 2, 2) - .putAll("CL", 1, 1, 2, 2, 3, 2) - .putAll("CM", 3, 4, 3, 2, 2, 2) - .putAll("CN", 2, 0, 2, 2, 3, 1) - .putAll("CO", 2, 2, 4, 2, 2, 2) - .putAll("CR", 2, 2, 4, 4, 2, 2) - .putAll("CU", 4, 4, 3, 2, 2, 2) - .putAll("CV", 2, 3, 1, 0, 2, 2) - .putAll("CW", 2, 2, 0, 0, 2, 2) - .putAll("CX", 1, 2, 2, 2, 2, 2) - .putAll("CY", 1, 0, 0, 0, 1, 2) - .putAll("CZ", 0, 0, 0, 0, 1, 2) - .putAll("DE", 0, 0, 2, 2, 1, 2) - .putAll("DJ", 4, 1, 4, 4, 2, 2) - .putAll("DK", 0, 0, 1, 0, 0, 2) - .putAll("DM", 1, 2, 2, 2, 2, 2) - .putAll("DO", 3, 4, 4, 4, 2, 2) - .putAll("DZ", 4, 3, 4, 4, 2, 2) - .putAll("EC", 2, 4, 2, 1, 2, 2) - .putAll("EE", 0, 0, 0, 0, 2, 2) - .putAll("EG", 3, 4, 2, 3, 2, 2) - .putAll("EH", 2, 2, 2, 2, 2, 2) - .putAll("ER", 4, 2, 2, 2, 2, 2) - .putAll("ES", 0, 1, 1, 1, 2, 2) - .putAll("ET", 4, 4, 3, 1, 2, 2) - .putAll("FI", 0, 0, 0, 1, 0, 2) - .putAll("FJ", 3, 1, 3, 3, 2, 2) - .putAll("FK", 3, 2, 2, 2, 2, 2) - .putAll("FM", 3, 2, 4, 2, 2, 2) - .putAll("FO", 0, 2, 0, 0, 2, 2) - .putAll("FR", 1, 1, 2, 1, 1, 1) - .putAll("GA", 2, 3, 1, 1, 2, 2) - .putAll("GB", 0, 0, 1, 1, 2, 3) - .putAll("GD", 1, 2, 2, 2, 2, 2) - .putAll("GE", 1, 1, 1, 3, 2, 2) - .putAll("GF", 2, 1, 2, 3, 2, 2) - .putAll("GG", 0, 2, 0, 0, 2, 2) - .putAll("GH", 3, 2, 3, 2, 2, 2) - .putAll("GI", 0, 2, 2, 2, 2, 2) - .putAll("GL", 1, 2, 0, 0, 2, 2) - .putAll("GM", 4, 2, 2, 4, 2, 2) - .putAll("GN", 4, 3, 4, 2, 2, 2) - .putAll("GP", 2, 1, 2, 3, 2, 2) - .putAll("GQ", 4, 2, 3, 4, 2, 2) - .putAll("GR", 1, 0, 0, 0, 2, 2) - .putAll("GT", 2, 3, 2, 1, 2, 2) - .putAll("GU", 1, 2, 4, 4, 2, 2) - .putAll("GW", 3, 4, 3, 3, 2, 2) - .putAll("GY", 3, 4, 1, 0, 2, 2) - .putAll("HK", 0, 1, 2, 3, 2, 0) - .putAll("HN", 3, 2, 3, 3, 2, 2) - .putAll("HR", 1, 0, 0, 0, 2, 2) - .putAll("HT", 4, 4, 4, 4, 2, 2) - .putAll("HU", 0, 0, 0, 1, 3, 2) - .putAll("ID", 3, 2, 3, 3, 3, 2) - .putAll("IE", 0, 1, 1, 1, 2, 2) - .putAll("IL", 1, 1, 2, 3, 4, 2) - .putAll("IM", 0, 2, 0, 1, 2, 2) - .putAll("IN", 1, 1, 3, 2, 4, 3) - .putAll("IO", 4, 2, 2, 2, 2, 2) - .putAll("IQ", 3, 3, 3, 3, 2, 2) - .putAll("IR", 3, 0, 1, 1, 3, 0) - .putAll("IS", 0, 0, 0, 0, 0, 2) - .putAll("IT", 0, 1, 0, 1, 1, 2) - .putAll("JE", 3, 2, 1, 2, 2, 2) - .putAll("JM", 3, 4, 4, 4, 2, 2) - .putAll("JO", 1, 0, 0, 1, 2, 2) - .putAll("JP", 0, 1, 0, 1, 1, 1) - .putAll("KE", 3, 3, 2, 2, 2, 2) - .putAll("KG", 2, 1, 1, 1, 2, 2) - .putAll("KH", 1, 1, 4, 2, 2, 2) - .putAll("KI", 4, 2, 4, 3, 2, 2) - .putAll("KM", 4, 2, 4, 3, 2, 2) - .putAll("KN", 2, 2, 2, 2, 2, 2) - .putAll("KP", 3, 2, 2, 2, 2, 2) - .putAll("KR", 0, 0, 1, 3, 4, 4) - .putAll("KW", 1, 1, 0, 0, 0, 2) - .putAll("KY", 1, 2, 0, 1, 2, 2) - .putAll("KZ", 1, 1, 2, 2, 2, 2) - .putAll("LA", 2, 2, 1, 2, 2, 2) - .putAll("LB", 3, 2, 1, 4, 2, 2) - .putAll("LC", 1, 2, 0, 0, 2, 2) - .putAll("LI", 0, 2, 2, 2, 2, 2) - .putAll("LK", 3, 1, 3, 4, 4, 2) - .putAll("LR", 3, 4, 4, 3, 2, 2) - .putAll("LS", 3, 3, 4, 3, 2, 2) - .putAll("LT", 0, 0, 0, 0, 2, 2) - .putAll("LU", 1, 0, 2, 2, 2, 2) - .putAll("LV", 0, 0, 0, 0, 2, 2) - .putAll("LY", 4, 2, 4, 3, 2, 2) - .putAll("MA", 3, 2, 2, 2, 2, 2) - .putAll("MC", 0, 2, 2, 0, 2, 2) - .putAll("MD", 1, 0, 0, 0, 2, 2) - .putAll("ME", 1, 0, 0, 1, 2, 2) - .putAll("MF", 1, 2, 1, 0, 2, 2) - .putAll("MG", 3, 4, 2, 2, 2, 2) - .putAll("MH", 3, 2, 2, 4, 2, 2) - .putAll("MK", 1, 0, 0, 0, 2, 2) - .putAll("ML", 4, 3, 3, 1, 2, 2) - .putAll("MM", 2, 4, 3, 3, 2, 2) - .putAll("MN", 2, 0, 1, 2, 2, 2) - .putAll("MO", 0, 2, 4, 4, 2, 2) - .putAll("MP", 0, 2, 2, 2, 2, 2) - .putAll("MQ", 2, 1, 2, 3, 2, 2) - .putAll("MR", 4, 1, 3, 4, 2, 2) - .putAll("MS", 1, 2, 2, 2, 2, 2) - .putAll("MT", 0, 0, 0, 0, 2, 2) - .putAll("MU", 3, 1, 1, 2, 2, 2) - .putAll("MV", 3, 4, 1, 4, 2, 2) - .putAll("MW", 4, 2, 1, 0, 2, 2) - .putAll("MX", 2, 4, 3, 4, 2, 2) - .putAll("MY", 2, 1, 3, 3, 2, 2) - .putAll("MZ", 3, 2, 2, 2, 2, 2) - .putAll("NA", 4, 3, 2, 2, 2, 2) - .putAll("NC", 3, 2, 4, 4, 2, 2) - .putAll("NE", 4, 4, 4, 4, 2, 2) - .putAll("NF", 2, 2, 2, 2, 2, 2) - .putAll("NG", 3, 4, 1, 1, 2, 2) - .putAll("NI", 2, 3, 4, 3, 2, 2) - .putAll("NL", 0, 0, 3, 2, 0, 4) - .putAll("NO", 0, 0, 2, 0, 0, 2) - .putAll("NP", 2, 1, 4, 3, 2, 2) - .putAll("NR", 3, 2, 2, 0, 2, 2) - .putAll("NU", 4, 2, 2, 2, 2, 2) - .putAll("NZ", 1, 0, 1, 2, 4, 2) - .putAll("OM", 2, 3, 1, 3, 4, 2) - .putAll("PA", 1, 3, 3, 3, 2, 2) - .putAll("PE", 2, 3, 4, 4, 4, 2) - .putAll("PF", 2, 3, 3, 1, 2, 2) - .putAll("PG", 4, 4, 3, 2, 2, 2) - .putAll("PH", 2, 2, 3, 3, 3, 2) - .putAll("PK", 3, 2, 3, 3, 2, 2) - .putAll("PL", 1, 1, 2, 2, 3, 2) - .putAll("PM", 0, 2, 2, 2, 2, 2) - .putAll("PR", 2, 3, 2, 2, 3, 3) - .putAll("PS", 3, 4, 1, 2, 2, 2) - .putAll("PT", 0, 1, 0, 0, 2, 2) - .putAll("PW", 2, 2, 4, 1, 2, 2) - .putAll("PY", 2, 2, 3, 2, 2, 2) - .putAll("QA", 2, 4, 2, 4, 4, 2) - .putAll("RE", 1, 1, 1, 2, 2, 2) - .putAll("RO", 0, 0, 1, 1, 1, 2) - .putAll("RS", 1, 0, 0, 0, 2, 2) - .putAll("RU", 0, 0, 0, 1, 2, 2) - .putAll("RW", 3, 4, 3, 0, 2, 2) - .putAll("SA", 2, 2, 1, 1, 2, 2) - .putAll("SB", 4, 2, 4, 3, 2, 2) - .putAll("SC", 4, 3, 0, 2, 2, 2) - .putAll("SD", 4, 4, 4, 4, 2, 2) - .putAll("SE", 0, 0, 0, 0, 0, 2) - .putAll("SG", 1, 1, 2, 3, 1, 4) - .putAll("SH", 4, 2, 2, 2, 2, 2) - .putAll("SI", 0, 0, 0, 0, 1, 2) - .putAll("SJ", 0, 2, 2, 2, 2, 2) - .putAll("SK", 0, 0, 0, 0, 0, 2) - .putAll("SL", 4, 3, 4, 1, 2, 2) - .putAll("SM", 0, 2, 2, 2, 2, 2) - .putAll("SN", 4, 4, 4, 4, 2, 2) - .putAll("SO", 3, 2, 3, 3, 2, 2) - .putAll("SR", 2, 3, 2, 2, 2, 2) - .putAll("SS", 4, 2, 2, 2, 2, 2) - .putAll("ST", 3, 2, 2, 2, 2, 2) - .putAll("SV", 2, 2, 3, 3, 2, 2) - .putAll("SX", 2, 2, 1, 0, 2, 2) - .putAll("SY", 4, 3, 4, 4, 2, 2) - .putAll("SZ", 4, 3, 2, 4, 2, 2) - .putAll("TC", 2, 2, 1, 0, 2, 2) - .putAll("TD", 4, 4, 4, 4, 2, 2) - .putAll("TG", 3, 3, 2, 0, 2, 2) - .putAll("TH", 0, 3, 2, 3, 3, 0) - .putAll("TJ", 4, 2, 4, 4, 2, 2) - .putAll("TL", 4, 3, 4, 4, 2, 2) - .putAll("TM", 4, 2, 4, 2, 2, 2) - .putAll("TN", 2, 2, 1, 1, 2, 2) - .putAll("TO", 4, 2, 3, 3, 2, 2) - .putAll("TR", 1, 1, 0, 1, 2, 2) - .putAll("TT", 1, 4, 1, 1, 2, 2) - .putAll("TV", 4, 2, 2, 2, 2, 2) - .putAll("TW", 0, 0, 0, 0, 0, 0) - .putAll("TZ", 3, 4, 3, 3, 2, 2) - .putAll("UA", 0, 3, 1, 1, 2, 2) - .putAll("UG", 3, 3, 3, 3, 2, 2) - .putAll("US", 1, 1, 2, 2, 3, 2) - .putAll("UY", 2, 2, 1, 2, 2, 2) - .putAll("UZ", 2, 2, 3, 4, 2, 2) - .putAll("VC", 1, 2, 2, 2, 2, 2) - .putAll("VE", 4, 4, 4, 4, 2, 2) - .putAll("VG", 2, 2, 1, 1, 2, 2) - .putAll("VI", 1, 2, 1, 3, 2, 2) - .putAll("VN", 0, 3, 3, 4, 2, 2) - .putAll("VU", 4, 2, 2, 1, 2, 2) - .putAll("WF", 4, 2, 2, 4, 2, 2) - .putAll("WS", 3, 1, 2, 1, 2, 2) - .putAll("XK", 1, 1, 1, 1, 2, 2) - .putAll("YE", 4, 4, 4, 4, 2, 2) - .putAll("YT", 4, 1, 1, 1, 2, 2) - .putAll("ZA", 3, 3, 1, 1, 1, 2) - .putAll("ZM", 3, 3, 4, 2, 2, 2) - .putAll("ZW", 3, 2, 4, 3, 2, 2) - .build(); + /** + * Returns initial bitrate group assignments for a {@code country}. The initial bitrate is a list + * of indexes for [Wifi, 2G, 3G, 4G, 5G_NSA, 5G_SA]. + */ + private static int[] getInitialBitrateCountryGroupAssignment(String country) { + switch (country) { + case "AE": + return new int[] {1, 4, 4, 4, 3, 2}; + case "AG": + return new int[] {2, 3, 1, 2, 2, 2}; + case "AM": + return new int[] {2, 3, 2, 4, 2, 2}; + case "AR": + return new int[] {2, 4, 1, 1, 2, 2}; + case "AS": + return new int[] {2, 2, 2, 3, 2, 2}; + case "AU": + return new int[] {0, 1, 0, 1, 2, 2}; + case "BE": + return new int[] {0, 0, 3, 3, 2, 2}; + case "BF": + return new int[] {4, 3, 4, 3, 2, 2}; + case "BH": + return new int[] {1, 2, 2, 4, 4, 2}; + case "BJ": + return new int[] {4, 4, 3, 4, 2, 2}; + case "BN": + return new int[] {3, 2, 1, 1, 2, 2}; + case "BO": + return new int[] {1, 3, 3, 2, 2, 2}; + case "BQ": + return new int[] {1, 2, 2, 0, 2, 2}; + case "BS": + return new int[] {4, 2, 2, 3, 2, 2}; + case "BT": + return new int[] {3, 1, 3, 2, 2, 2}; + case "BY": + return new int[] {0, 1, 1, 3, 2, 2}; + case "BZ": + return new int[] {2, 4, 2, 2, 2, 2}; + case "CA": + return new int[] {0, 2, 1, 2, 4, 1}; + case "CD": + return new int[] {4, 2, 3, 1, 2, 2}; + case "CF": + return new int[] {4, 2, 3, 2, 2, 2}; + case "CI": + return new int[] {3, 3, 3, 4, 2, 2}; + case "CK": + return new int[] {2, 2, 2, 1, 2, 2}; + case "AO": + case "CM": + return new int[] {3, 4, 3, 2, 2, 2}; + case "CN": + return new int[] {2, 0, 2, 2, 3, 1}; + case "CO": + return new int[] {2, 2, 4, 2, 2, 2}; + case "CR": + return new int[] {2, 2, 4, 4, 2, 2}; + case "CV": + return new int[] {2, 3, 1, 0, 2, 2}; + case "CW": + return new int[] {2, 2, 0, 0, 2, 2}; + case "CY": + return new int[] {1, 0, 0, 0, 1, 2}; + case "DE": + return new int[] {0, 0, 2, 2, 1, 2}; + case "DJ": + return new int[] {4, 1, 4, 4, 2, 2}; + case "DK": + return new int[] {0, 0, 1, 0, 0, 2}; + case "EC": + return new int[] {2, 4, 2, 1, 2, 2}; + case "EG": + return new int[] {3, 4, 2, 3, 2, 2}; + case "ET": + return new int[] {4, 4, 3, 1, 2, 2}; + case "FI": + return new int[] {0, 0, 0, 1, 0, 2}; + case "FJ": + return new int[] {3, 1, 3, 3, 2, 2}; + case "FM": + return new int[] {3, 2, 4, 2, 2, 2}; + case "FR": + return new int[] {1, 1, 2, 1, 1, 1}; + case "GA": + return new int[] {2, 3, 1, 1, 2, 2}; + case "GB": + return new int[] {0, 0, 1, 1, 2, 3}; + case "GE": + return new int[] {1, 1, 1, 3, 2, 2}; + case "BB": + case "FO": + case "GG": + return new int[] {0, 2, 0, 0, 2, 2}; + case "GH": + return new int[] {3, 2, 3, 2, 2, 2}; + case "GN": + return new int[] {4, 3, 4, 2, 2, 2}; + case "GQ": + return new int[] {4, 2, 3, 4, 2, 2}; + case "GT": + return new int[] {2, 3, 2, 1, 2, 2}; + case "AW": + case "GU": + return new int[] {1, 2, 4, 4, 2, 2}; + case "BW": + case "GY": + return new int[] {3, 4, 1, 0, 2, 2}; + case "HK": + return new int[] {0, 1, 2, 3, 2, 0}; + case "HU": + return new int[] {0, 0, 0, 1, 3, 2}; + case "ID": + return new int[] {3, 2, 3, 3, 3, 2}; + case "ES": + case "IE": + return new int[] {0, 1, 1, 1, 2, 2}; + case "IL": + return new int[] {1, 1, 2, 3, 4, 2}; + case "IM": + return new int[] {0, 2, 0, 1, 2, 2}; + case "IN": + return new int[] {1, 1, 3, 2, 4, 3}; + case "IR": + return new int[] {3, 0, 1, 1, 3, 0}; + case "IT": + return new int[] {0, 1, 0, 1, 1, 2}; + case "JE": + return new int[] {3, 2, 1, 2, 2, 2}; + case "DO": + case "JM": + return new int[] {3, 4, 4, 4, 2, 2}; + case "JP": + return new int[] {0, 1, 0, 1, 1, 1}; + case "KE": + return new int[] {3, 3, 2, 2, 2, 2}; + case "KG": + return new int[] {2, 1, 1, 1, 2, 2}; + case "KH": + return new int[] {1, 1, 4, 2, 2, 2}; + case "KR": + return new int[] {0, 0, 1, 3, 4, 4}; + case "KW": + return new int[] {1, 1, 0, 0, 0, 2}; + case "AL": + case "BA": + case "KY": + return new int[] {1, 2, 0, 1, 2, 2}; + case "KZ": + return new int[] {1, 1, 2, 2, 2, 2}; + case "LB": + return new int[] {3, 2, 1, 4, 2, 2}; + case "AD": + case "BM": + case "GL": + case "LC": + return new int[] {1, 2, 0, 0, 2, 2}; + case "LK": + return new int[] {3, 1, 3, 4, 4, 2}; + case "LR": + return new int[] {3, 4, 4, 3, 2, 2}; + case "LS": + return new int[] {3, 3, 4, 3, 2, 2}; + case "LU": + return new int[] {1, 0, 2, 2, 2, 2}; + case "MC": + return new int[] {0, 2, 2, 0, 2, 2}; + case "JO": + case "ME": + return new int[] {1, 0, 0, 1, 2, 2}; + case "MF": + return new int[] {1, 2, 1, 0, 2, 2}; + case "MG": + return new int[] {3, 4, 2, 2, 2, 2}; + case "MH": + return new int[] {3, 2, 2, 4, 2, 2}; + case "ML": + return new int[] {4, 3, 3, 1, 2, 2}; + case "MM": + return new int[] {2, 4, 3, 3, 2, 2}; + case "MN": + return new int[] {2, 0, 1, 2, 2, 2}; + case "MO": + return new int[] {0, 2, 4, 4, 2, 2}; + case "GF": + case "GP": + case "MQ": + return new int[] {2, 1, 2, 3, 2, 2}; + case "MR": + return new int[] {4, 1, 3, 4, 2, 2}; + case "EE": + case "LT": + case "LV": + case "MT": + return new int[] {0, 0, 0, 0, 2, 2}; + case "MU": + return new int[] {3, 1, 1, 2, 2, 2}; + case "MV": + return new int[] {3, 4, 1, 4, 2, 2}; + case "MW": + return new int[] {4, 2, 1, 0, 2, 2}; + case "CG": + case "MX": + return new int[] {2, 4, 3, 4, 2, 2}; + case "BD": + case "MY": + return new int[] {2, 1, 3, 3, 2, 2}; + case "NA": + return new int[] {4, 3, 2, 2, 2, 2}; + case "AZ": + case "NC": + return new int[] {3, 2, 4, 4, 2, 2}; + case "NG": + return new int[] {3, 4, 1, 1, 2, 2}; + case "NI": + return new int[] {2, 3, 4, 3, 2, 2}; + case "NL": + return new int[] {0, 0, 3, 2, 0, 4}; + case "NO": + return new int[] {0, 0, 2, 0, 0, 2}; + case "NP": + return new int[] {2, 1, 4, 3, 2, 2}; + case "NR": + return new int[] {3, 2, 2, 0, 2, 2}; + case "NZ": + return new int[] {1, 0, 1, 2, 4, 2}; + case "OM": + return new int[] {2, 3, 1, 3, 4, 2}; + case "PA": + return new int[] {1, 3, 3, 3, 2, 2}; + case "PE": + return new int[] {2, 3, 4, 4, 4, 2}; + case "PF": + return new int[] {2, 3, 3, 1, 2, 2}; + case "CU": + case "PG": + return new int[] {4, 4, 3, 2, 2, 2}; + case "PH": + return new int[] {2, 2, 3, 3, 3, 2}; + case "PR": + return new int[] {2, 3, 2, 2, 3, 3}; + case "PS": + return new int[] {3, 4, 1, 2, 2, 2}; + case "PT": + return new int[] {0, 1, 0, 0, 2, 2}; + case "PW": + return new int[] {2, 2, 4, 1, 2, 2}; + case "PY": + return new int[] {2, 2, 3, 2, 2, 2}; + case "QA": + return new int[] {2, 4, 2, 4, 4, 2}; + case "RE": + return new int[] {1, 1, 1, 2, 2, 2}; + case "RO": + return new int[] {0, 0, 1, 1, 1, 2}; + case "GR": + case "HR": + case "MD": + case "MK": + case "RS": + return new int[] {1, 0, 0, 0, 2, 2}; + case "RU": + return new int[] {0, 0, 0, 1, 2, 2}; + case "RW": + return new int[] {3, 4, 3, 0, 2, 2}; + case "KI": + case "KM": + case "LY": + case "SB": + return new int[] {4, 2, 4, 3, 2, 2}; + case "SC": + return new int[] {4, 3, 0, 2, 2, 2}; + case "SG": + return new int[] {1, 1, 2, 3, 1, 4}; + case "BG": + case "CZ": + case "SI": + return new int[] {0, 0, 0, 0, 1, 2}; + case "AT": + case "CH": + case "IS": + case "SE": + case "SK": + return new int[] {0, 0, 0, 0, 0, 2}; + case "SL": + return new int[] {4, 3, 4, 1, 2, 2}; + case "AX": + case "GI": + case "LI": + case "MP": + case "PM": + case "SJ": + case "SM": + return new int[] {0, 2, 2, 2, 2, 2}; + case "HN": + case "PK": + case "SO": + return new int[] {3, 2, 3, 3, 2, 2}; + case "BR": + case "SR": + return new int[] {2, 3, 2, 2, 2, 2}; + case "FK": + case "KP": + case "MA": + case "MZ": + case "ST": + return new int[] {3, 2, 2, 2, 2, 2}; + case "SV": + return new int[] {2, 2, 3, 3, 2, 2}; + case "SZ": + return new int[] {4, 3, 2, 4, 2, 2}; + case "SX": + case "TC": + return new int[] {2, 2, 1, 0, 2, 2}; + case "TG": + return new int[] {3, 3, 2, 0, 2, 2}; + case "TH": + return new int[] {0, 3, 2, 3, 3, 0}; + case "TJ": + return new int[] {4, 2, 4, 4, 2, 2}; + case "BI": + case "DZ": + case "SY": + case "TL": + return new int[] {4, 3, 4, 4, 2, 2}; + case "TM": + return new int[] {4, 2, 4, 2, 2, 2}; + case "TO": + return new int[] {4, 2, 3, 3, 2, 2}; + case "TR": + return new int[] {1, 1, 0, 1, 2, 2}; + case "TT": + return new int[] {1, 4, 1, 1, 2, 2}; + case "AQ": + case "ER": + case "IO": + case "NU": + case "SH": + case "SS": + case "TV": + return new int[] {4, 2, 2, 2, 2, 2}; + case "TW": + return new int[] {0, 0, 0, 0, 0, 0}; + case "GW": + case "TZ": + return new int[] {3, 4, 3, 3, 2, 2}; + case "UA": + return new int[] {0, 3, 1, 1, 2, 2}; + case "IQ": + case "UG": + return new int[] {3, 3, 3, 3, 2, 2}; + case "CL": + case "PL": + case "US": + return new int[] {1, 1, 2, 2, 3, 2}; + case "LA": + case "UY": + return new int[] {2, 2, 1, 2, 2, 2}; + case "UZ": + return new int[] {2, 2, 3, 4, 2, 2}; + case "AI": + case "BL": + case "CX": + case "DM": + case "GD": + case "MS": + case "VC": + return new int[] {1, 2, 2, 2, 2, 2}; + case "SA": + case "TN": + case "VG": + return new int[] {2, 2, 1, 1, 2, 2}; + case "VI": + return new int[] {1, 2, 1, 3, 2, 2}; + case "VN": + return new int[] {0, 3, 3, 4, 2, 2}; + case "VU": + return new int[] {4, 2, 2, 1, 2, 2}; + case "GM": + case "WF": + return new int[] {4, 2, 2, 4, 2, 2}; + case "WS": + return new int[] {3, 1, 2, 1, 2, 2}; + case "XK": + return new int[] {1, 1, 1, 1, 2, 2}; + case "AF": + case "HT": + case "NE": + case "SD": + case "SN": + case "TD": + case "VE": + case "YE": + return new int[] {4, 4, 4, 4, 2, 2}; + case "YT": + return new int[] {4, 1, 1, 1, 2, 2}; + case "ZA": + return new int[] {3, 3, 1, 1, 1, 2}; + case "ZM": + return new int[] {3, 3, 4, 2, 2, 2}; + case "ZW": + return new int[] {3, 2, 4, 3, 2, 2}; + default: + return new int[] {2, 2, 2, 2, 2, 2}; + } } } From 623be98d536c6c9c846a56aead8b2b23bedfff20 Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 2 Nov 2021 11:28:50 +0000 Subject: [PATCH 3/3] Suppress lint warning about IntDef assignment. The values returned by the framework method are equivalent to the local IntDef values. PiperOrigin-RevId: 407048748 --- .../com/google/android/exoplayer2/drm/FrameworkMediaDrm.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/drm/FrameworkMediaDrm.java b/library/core/src/main/java/com/google/android/exoplayer2/drm/FrameworkMediaDrm.java index e4ccaf1853..9cc9910443 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/drm/FrameworkMediaDrm.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/drm/FrameworkMediaDrm.java @@ -182,6 +182,8 @@ public final class FrameworkMediaDrm implements ExoMediaDrm { mediaDrm.closeSession(sessionId); } + // Return values of MediaDrm.KeyRequest.getRequestType are equal to KeyRequest.RequestType. + @SuppressLint("WrongConstant") @Override public KeyRequest getKeyRequest( byte[] scope,