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
This commit is contained in:
ibaker 2021-11-02 10:27:56 +00:00 committed by Ian Baker
parent 4f46e679a6
commit 686f2ca96d
36 changed files with 849 additions and 806 deletions

View File

@ -261,7 +261,7 @@ import java.util.ArrayList;
int playbackState = currentPlayer.getPlaybackState(); int playbackState = currentPlayer.getPlaybackState();
maybeSetCurrentItemAndNotify( maybeSetCurrentItemAndNotify(
playbackState != Player.STATE_IDLE && playbackState != Player.STATE_ENDED playbackState != Player.STATE_IDLE && playbackState != Player.STATE_ENDED
? currentPlayer.getCurrentWindowIndex() ? currentPlayer.getCurrentMediaItemIndex()
: C.INDEX_UNSET); : C.INDEX_UNSET);
} }
@ -281,7 +281,7 @@ import java.util.ArrayList;
// Player state management. // Player state management.
long playbackPositionMs = C.TIME_UNSET; long playbackPositionMs = C.TIME_UNSET;
int windowIndex = C.INDEX_UNSET; int currentItemIndex = C.INDEX_UNSET;
boolean playWhenReady = false; boolean playWhenReady = false;
Player previousPlayer = this.currentPlayer; Player previousPlayer = this.currentPlayer;
@ -291,10 +291,10 @@ import java.util.ArrayList;
if (playbackState != Player.STATE_ENDED) { if (playbackState != Player.STATE_ENDED) {
playbackPositionMs = previousPlayer.getCurrentPosition(); playbackPositionMs = previousPlayer.getCurrentPosition();
playWhenReady = previousPlayer.getPlayWhenReady(); playWhenReady = previousPlayer.getPlayWhenReady();
windowIndex = previousPlayer.getCurrentWindowIndex(); currentItemIndex = previousPlayer.getCurrentMediaItemIndex();
if (windowIndex != currentItemIndex) { if (currentItemIndex != this.currentItemIndex) {
playbackPositionMs = C.TIME_UNSET; playbackPositionMs = C.TIME_UNSET;
windowIndex = currentItemIndex; currentItemIndex = this.currentItemIndex;
} }
} }
previousPlayer.stop(); previousPlayer.stop();
@ -304,7 +304,7 @@ import java.util.ArrayList;
this.currentPlayer = currentPlayer; this.currentPlayer = currentPlayer;
// Media queue management. // Media queue management.
currentPlayer.setMediaItems(mediaQueue, windowIndex, playbackPositionMs); currentPlayer.setMediaItems(mediaQueue, currentItemIndex, playbackPositionMs);
currentPlayer.setPlayWhenReady(playWhenReady); currentPlayer.setPlayWhenReady(playWhenReady);
currentPlayer.prepare(); currentPlayer.prepare();
} }

View File

@ -65,7 +65,7 @@ public class PlayerActivity extends AppCompatActivity
// Saved instance state keys. // Saved instance state keys.
private static final String KEY_TRACK_SELECTION_PARAMETERS = "track_selection_parameters"; 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_POSITION = "position";
private static final String KEY_AUTO_PLAY = "auto_play"; private static final String KEY_AUTO_PLAY = "auto_play";
@ -83,7 +83,7 @@ public class PlayerActivity extends AppCompatActivity
private DebugTextViewHelper debugViewHelper; private DebugTextViewHelper debugViewHelper;
private TracksInfo lastSeenTracksInfo; private TracksInfo lastSeenTracksInfo;
private boolean startAutoPlay; private boolean startAutoPlay;
private int startWindow; private int startItemIndex;
private long startPosition; private long startPosition;
// For ad playback only. // For ad playback only.
@ -114,7 +114,7 @@ public class PlayerActivity extends AppCompatActivity
DefaultTrackSelector.Parameters.CREATOR.fromBundle( DefaultTrackSelector.Parameters.CREATOR.fromBundle(
savedInstanceState.getBundle(KEY_TRACK_SELECTION_PARAMETERS)); savedInstanceState.getBundle(KEY_TRACK_SELECTION_PARAMETERS));
startAutoPlay = savedInstanceState.getBoolean(KEY_AUTO_PLAY); startAutoPlay = savedInstanceState.getBoolean(KEY_AUTO_PLAY);
startWindow = savedInstanceState.getInt(KEY_WINDOW); startItemIndex = savedInstanceState.getInt(KEY_ITEM_INDEX);
startPosition = savedInstanceState.getLong(KEY_POSITION); startPosition = savedInstanceState.getLong(KEY_POSITION);
} else { } else {
trackSelectionParameters = trackSelectionParameters =
@ -206,7 +206,7 @@ public class PlayerActivity extends AppCompatActivity
updateStartPosition(); updateStartPosition();
outState.putBundle(KEY_TRACK_SELECTION_PARAMETERS, trackSelectionParameters.toBundle()); outState.putBundle(KEY_TRACK_SELECTION_PARAMETERS, trackSelectionParameters.toBundle());
outState.putBoolean(KEY_AUTO_PLAY, startAutoPlay); outState.putBoolean(KEY_AUTO_PLAY, startAutoPlay);
outState.putInt(KEY_WINDOW, startWindow); outState.putInt(KEY_ITEM_INDEX, startItemIndex);
outState.putLong(KEY_POSITION, startPosition); outState.putLong(KEY_POSITION, startPosition);
} }
@ -282,9 +282,9 @@ public class PlayerActivity extends AppCompatActivity
debugViewHelper = new DebugTextViewHelper(player, debugTextView); debugViewHelper = new DebugTextViewHelper(player, debugTextView);
debugViewHelper.start(); debugViewHelper.start();
} }
boolean haveStartPosition = startWindow != C.INDEX_UNSET; boolean haveStartPosition = startItemIndex != C.INDEX_UNSET;
if (haveStartPosition) { if (haveStartPosition) {
player.seekTo(startWindow, startPosition); player.seekTo(startItemIndex, startPosition);
} }
player.setMediaItems(mediaItems, /* resetPosition= */ !haveStartPosition); player.setMediaItems(mediaItems, /* resetPosition= */ !haveStartPosition);
player.prepare(); player.prepare();
@ -382,14 +382,14 @@ public class PlayerActivity extends AppCompatActivity
private void updateStartPosition() { private void updateStartPosition() {
if (player != null) { if (player != null) {
startAutoPlay = player.getPlayWhenReady(); startAutoPlay = player.getPlayWhenReady();
startWindow = player.getCurrentWindowIndex(); startItemIndex = player.getCurrentMediaItemIndex();
startPosition = Math.max(0, player.getContentPosition()); startPosition = Math.max(0, player.getContentPosition());
} }
} }
protected void clearStartPosition() { protected void clearStartPosition() {
startAutoPlay = true; startAutoPlay = true;
startWindow = C.INDEX_UNSET; startItemIndex = C.INDEX_UNSET;
startPosition = C.TIME_UNSET; startPosition = C.TIME_UNSET;
} }

View File

@ -204,7 +204,7 @@ class PlayerActivity : AppCompatActivity() {
returnConvertView.findViewById<TextView>(R.id.media_item).text = mediaItem.mediaMetadata.title returnConvertView.findViewById<TextView>(R.id.media_item).text = mediaItem.mediaMetadata.title
if (position == controller?.currentWindowIndex) { if (position == controller?.currentMediaItemIndex) {
returnConvertView.setBackgroundColor(ContextCompat.getColor(context, R.color.white)) returnConvertView.setBackgroundColor(ContextCompat.getColor(context, R.color.white))
returnConvertView returnConvertView
.findViewById<TextView>(R.id.media_item) .findViewById<TextView>(R.id.media_item)

View File

@ -320,9 +320,9 @@ public final class CastPlayer extends BasePlayer {
@Override @Override
public void setMediaItems(List<MediaItem> mediaItems, boolean resetPosition) { public void setMediaItems(List<MediaItem> mediaItems, boolean resetPosition) {
int windowIndex = resetPosition ? 0 : getCurrentWindowIndex(); int mediaItemIndex = resetPosition ? 0 : getCurrentMediaItemIndex();
long startPositionMs = resetPosition ? C.TIME_UNSET : getContentPosition(); long startPositionMs = resetPosition ? C.TIME_UNSET : getContentPosition();
setMediaItems(mediaItems, windowIndex, startPositionMs); setMediaItems(mediaItems, mediaItemIndex, startPositionMs);
} }
@Override @Override
@ -445,7 +445,7 @@ public final class CastPlayer extends BasePlayer {
// in RemoteMediaClient. // in RemoteMediaClient.
positionMs = positionMs != C.TIME_UNSET ? positionMs : 0; positionMs = positionMs != C.TIME_UNSET ? positionMs : 0;
if (mediaStatus != null) { if (mediaStatus != null) {
if (getCurrentWindowIndex() != mediaItemIndex) { if (getCurrentMediaItemIndex() != mediaItemIndex) {
remoteMediaClient remoteMediaClient
.queueJumpToItem( .queueJumpToItem(
(int) currentTimeline.getPeriod(mediaItemIndex, period).uid, positionMs, null) (int) currentTimeline.getPeriod(mediaItemIndex, period).uid, positionMs, null)
@ -638,7 +638,7 @@ public final class CastPlayer extends BasePlayer {
@Override @Override
public int getCurrentPeriodIndex() { public int getCurrentPeriodIndex() {
return getCurrentWindowIndex(); return getCurrentMediaItemIndex();
} }
@Override @Override
@ -1105,15 +1105,15 @@ public final class CastPlayer extends BasePlayer {
@Nullable @Nullable
private PendingResult<MediaChannelResult> setMediaItemsInternal( private PendingResult<MediaChannelResult> setMediaItemsInternal(
MediaQueueItem[] mediaQueueItems, MediaQueueItem[] mediaQueueItems,
int startWindowIndex, int startIndex,
long startPositionMs, long startPositionMs,
@RepeatMode int repeatMode) { @RepeatMode int repeatMode) {
if (remoteMediaClient == null || mediaQueueItems.length == 0) { if (remoteMediaClient == null || mediaQueueItems.length == 0) {
return null; return null;
} }
startPositionMs = startPositionMs == C.TIME_UNSET ? 0 : startPositionMs; startPositionMs = startPositionMs == C.TIME_UNSET ? 0 : startPositionMs;
if (startWindowIndex == C.INDEX_UNSET) { if (startIndex == C.INDEX_UNSET) {
startWindowIndex = getCurrentWindowIndex(); startIndex = getCurrentMediaItemIndex();
startPositionMs = getCurrentPosition(); startPositionMs = getCurrentPosition();
} }
Timeline currentTimeline = getCurrentTimeline(); Timeline currentTimeline = getCurrentTimeline();
@ -1122,7 +1122,7 @@ public final class CastPlayer extends BasePlayer {
} }
return remoteMediaClient.queueLoad( return remoteMediaClient.queueLoad(
mediaQueueItems, mediaQueueItems,
min(startWindowIndex, mediaQueueItems.length - 1), min(startIndex, mediaQueueItems.length - 1),
getCastRepeatMode(repeatMode), getCastRepeatMode(repeatMode),
startPositionMs, startPositionMs,
/* customData= */ null); /* customData= */ null);
@ -1182,7 +1182,7 @@ public final class CastPlayer extends BasePlayer {
} }
return new PositionInfo( return new PositionInfo(
newWindowUid, newWindowUid,
getCurrentWindowIndex(), getCurrentMediaItemIndex(),
newMediaItem, newMediaItem,
newPeriodUid, newPeriodUid,
getCurrentPeriodIndex(), getCurrentPeriodIndex(),

View File

@ -120,7 +120,7 @@ public abstract class BasePlayer implements Player {
@Override @Override
public final void seekToDefaultPosition() { public final void seekToDefaultPosition() {
seekToDefaultPosition(getCurrentWindowIndex()); seekToDefaultPosition(getCurrentMediaItemIndex());
} }
@Override @Override
@ -130,7 +130,7 @@ public abstract class BasePlayer implements Player {
@Override @Override
public final void seekTo(long positionMs) { public final void seekTo(long positionMs) {
seekTo(getCurrentWindowIndex(), positionMs); seekTo(getCurrentMediaItemIndex(), positionMs);
} }
@Override @Override
@ -186,13 +186,13 @@ public abstract class BasePlayer implements Player {
if (timeline.isEmpty() || isPlayingAd()) { if (timeline.isEmpty() || isPlayingAd()) {
return; return;
} }
boolean hasPreviousWindow = hasPreviousWindow(); boolean hasPreviousMediaItem = hasPreviousMediaItem();
if (isCurrentWindowLive() && !isCurrentWindowSeekable()) { if (isCurrentMediaItemLive() && !isCurrentMediaItemSeekable()) {
if (hasPreviousWindow) { if (hasPreviousMediaItem) {
seekToPreviousWindow(); seekToPreviousMediaItem();
} }
} else if (hasPreviousWindow && getCurrentPosition() <= getMaxSeekToPreviousPosition()) { } else if (hasPreviousMediaItem && getCurrentPosition() <= getMaxSeekToPreviousPosition()) {
seekToPreviousWindow(); seekToPreviousMediaItem();
} else { } else {
seekTo(/* positionMs= */ 0); seekTo(/* positionMs= */ 0);
} }
@ -241,9 +241,9 @@ public abstract class BasePlayer implements Player {
if (timeline.isEmpty() || isPlayingAd()) { if (timeline.isEmpty() || isPlayingAd()) {
return; return;
} }
if (hasNextWindow()) { if (hasNextMediaItem()) {
seekToNextWindow(); seekToNextMediaItem();
} else if (isCurrentWindowLive() && isCurrentWindowDynamic()) { } else if (isCurrentMediaItemLive() && isCurrentMediaItemDynamic()) {
seekToDefaultPosition(); seekToDefaultPosition();
} }
} }
@ -295,7 +295,7 @@ public abstract class BasePlayer implements Player {
Timeline timeline = getCurrentTimeline(); Timeline timeline = getCurrentTimeline();
return timeline.isEmpty() return timeline.isEmpty()
? null ? null
: timeline.getWindow(getCurrentWindowIndex(), window).mediaItem; : timeline.getWindow(getCurrentMediaItemIndex(), window).mediaItem;
} }
@Override @Override
@ -312,7 +312,9 @@ public abstract class BasePlayer implements Player {
@Nullable @Nullable
public final Object getCurrentManifest() { public final Object getCurrentManifest() {
Timeline timeline = getCurrentTimeline(); Timeline timeline = getCurrentTimeline();
return timeline.isEmpty() ? null : timeline.getWindow(getCurrentWindowIndex(), window).manifest; return timeline.isEmpty()
? null
: timeline.getWindow(getCurrentMediaItemIndex(), window).manifest;
} }
@Override @Override
@ -354,7 +356,8 @@ public abstract class BasePlayer implements Player {
if (timeline.isEmpty()) { if (timeline.isEmpty()) {
return C.TIME_UNSET; return C.TIME_UNSET;
} }
long windowStartTimeMs = timeline.getWindow(getCurrentWindowIndex(), window).windowStartTimeMs; long windowStartTimeMs =
timeline.getWindow(getCurrentMediaItemIndex(), window).windowStartTimeMs;
if (windowStartTimeMs == C.TIME_UNSET) { if (windowStartTimeMs == C.TIME_UNSET) {
return C.TIME_UNSET; return C.TIME_UNSET;
} }
@ -378,7 +381,7 @@ public abstract class BasePlayer implements Player {
Timeline timeline = getCurrentTimeline(); Timeline timeline = getCurrentTimeline();
return timeline.isEmpty() return timeline.isEmpty()
? C.TIME_UNSET ? C.TIME_UNSET
: timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); : timeline.getWindow(getCurrentMediaItemIndex(), window).getDurationMs();
} }
/** /**
@ -391,22 +394,24 @@ public abstract class BasePlayer implements Player {
return new Commands.Builder() return new Commands.Builder()
.addAll(permanentAvailableCommands) .addAll(permanentAvailableCommands)
.addIf(COMMAND_SEEK_TO_DEFAULT_POSITION, !isPlayingAd()) .addIf(COMMAND_SEEK_TO_DEFAULT_POSITION, !isPlayingAd())
.addIf(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, isCurrentWindowSeekable() && !isPlayingAd()) .addIf(COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, isCurrentMediaItemSeekable() && !isPlayingAd())
.addIf(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, hasPreviousWindow() && !isPlayingAd()) .addIf(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, hasPreviousMediaItem() && !isPlayingAd())
.addIf( .addIf(
COMMAND_SEEK_TO_PREVIOUS, COMMAND_SEEK_TO_PREVIOUS,
!getCurrentTimeline().isEmpty() !getCurrentTimeline().isEmpty()
&& (hasPreviousWindow() || !isCurrentWindowLive() || isCurrentWindowSeekable()) && (hasPreviousMediaItem()
|| !isCurrentMediaItemLive()
|| isCurrentMediaItemSeekable())
&& !isPlayingAd()) && !isPlayingAd())
.addIf(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, hasNextWindow() && !isPlayingAd()) .addIf(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, hasNextMediaItem() && !isPlayingAd())
.addIf( .addIf(
COMMAND_SEEK_TO_NEXT, COMMAND_SEEK_TO_NEXT,
!getCurrentTimeline().isEmpty() !getCurrentTimeline().isEmpty()
&& (hasNextWindow() || (isCurrentWindowLive() && isCurrentWindowDynamic())) && (hasNextMediaItem() || (isCurrentMediaItemLive() && isCurrentMediaItemDynamic()))
&& !isPlayingAd()) && !isPlayingAd())
.addIf(COMMAND_SEEK_TO_MEDIA_ITEM, !isPlayingAd()) .addIf(COMMAND_SEEK_TO_MEDIA_ITEM, !isPlayingAd())
.addIf(COMMAND_SEEK_BACK, isCurrentWindowSeekable() && !isPlayingAd()) .addIf(COMMAND_SEEK_BACK, isCurrentMediaItemSeekable() && !isPlayingAd())
.addIf(COMMAND_SEEK_FORWARD, isCurrentWindowSeekable() && !isPlayingAd()) .addIf(COMMAND_SEEK_FORWARD, isCurrentMediaItemSeekable() && !isPlayingAd())
.build(); .build();
} }

View File

@ -1182,7 +1182,7 @@ public interface ExoPlayer extends Player {
* @param mediaSources The new {@link MediaSource MediaSources}. * @param mediaSources The new {@link MediaSource MediaSources}.
* @param resetPosition Whether the playback position should be reset to the default position in * @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 * 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()}.
*/ */
@UnstableApi @UnstableApi
void setMediaSources(List<MediaSource> mediaSources, boolean resetPosition); void setMediaSources(List<MediaSource> mediaSources, boolean resetPosition);
@ -1191,15 +1191,16 @@ public interface ExoPlayer extends Player {
* Clears the playlist and adds the specified {@link MediaSource MediaSources}. * Clears the playlist and adds the specified {@link MediaSource MediaSources}.
* *
* @param mediaSources The new {@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 * @param startMediaItemIndex The media item index to start playback from. If {@link
* passed, the current position is not reset. * C#INDEX_UNSET} is passed, the current position is not reset.
* @param startPositionMs The position in milliseconds to start playback from. If {@link * @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 * C#TIME_UNSET} is passed, the default position of the given media item is used. In any case,
* {@code startWindowIndex} is set to {@link C#INDEX_UNSET}, this parameter is ignored and the * if {@code startMediaItemIndex} is set to {@link C#INDEX_UNSET}, this parameter is ignored
* position is not reset at all. * and the position is not reset at all.
*/ */
@UnstableApi @UnstableApi
void setMediaSources(List<MediaSource> mediaSources, int startWindowIndex, long startPositionMs); void setMediaSources(
List<MediaSource> mediaSources, int startMediaItemIndex, long startPositionMs);
/** /**
* Clears the playlist, adds the specified {@link MediaSource} and resets the position to the * Clears the playlist, adds the specified {@link MediaSource} and resets the position to the
@ -1224,7 +1225,7 @@ public interface ExoPlayer extends Player {
* *
* @param mediaSource The new {@link MediaSource}. * @param mediaSource The new {@link MediaSource}.
* @param resetPosition Whether the playback position should be reset to the default position. If * @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()}. * and {@link #getCurrentPosition()}.
*/ */
@UnstableApi @UnstableApi
@ -1411,9 +1412,9 @@ public interface ExoPlayer extends Player {
* will be delivered immediately without blocking on the playback thread. The default {@link * 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 * 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 * position is specified with {@link PlayerMessage#setPosition(long)}, the message will be
* delivered at this position in the current window defined by {@link #getCurrentWindowIndex()}. * delivered at this position in the current media item defined by {@link
* Alternatively, the message can be sent at a specific window using {@link * #getCurrentMediaItemIndex()}. Alternatively, the message can be sent at a specific mediaItem
* PlayerMessage#setPosition(int, long)}. * using {@link PlayerMessage#setPosition(int, long)}.
*/ */
@UnstableApi @UnstableApi
PlayerMessage createMessage(PlayerMessage.Target target); PlayerMessage createMessage(PlayerMessage.Target target);

View File

@ -550,7 +550,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
playbackInfo, playbackInfo,
timeline, timeline,
getPeriodPositionOrMaskWindowPosition( getPeriodPositionOrMaskWindowPosition(
timeline, getCurrentWindowIndex(), getCurrentPosition())); timeline, getCurrentMediaItemIndex(), getCurrentPosition()));
pendingOperationAcks++; pendingOperationAcks++;
this.shuffleOrder = shuffleOrder; this.shuffleOrder = shuffleOrder;
internalPlayer.setShuffleOrder(shuffleOrder); internalPlayer.setShuffleOrder(shuffleOrder);
@ -675,7 +675,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Player.State @Player.State
int newPlaybackState = int newPlaybackState =
getPlaybackState() == Player.STATE_IDLE ? Player.STATE_IDLE : Player.STATE_BUFFERING; getPlaybackState() == Player.STATE_IDLE ? Player.STATE_IDLE : Player.STATE_BUFFERING;
int oldMaskingWindowIndex = getCurrentWindowIndex(); int oldMaskingMediaItemIndex = getCurrentMediaItemIndex();
PlaybackInfo newPlaybackInfo = playbackInfo.copyWithPlaybackState(newPlaybackState); PlaybackInfo newPlaybackInfo = playbackInfo.copyWithPlaybackState(newPlaybackState);
newPlaybackInfo = newPlaybackInfo =
maskTimelineAndPosition( maskTimelineAndPosition(
@ -691,7 +691,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
/* positionDiscontinuity= */ true, /* positionDiscontinuity= */ true,
/* positionDiscontinuityReason= */ DISCONTINUITY_REASON_SEEK, /* positionDiscontinuityReason= */ DISCONTINUITY_REASON_SEEK,
/* discontinuityWindowStartPositionUs= */ getCurrentPositionUsInternal(newPlaybackInfo), /* discontinuityWindowStartPositionUs= */ getCurrentPositionUsInternal(newPlaybackInfo),
oldMaskingWindowIndex); oldMaskingMediaItemIndex);
} }
@Override @Override
@ -852,7 +852,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
internalPlayer, internalPlayer,
target, target,
playbackInfo.timeline, playbackInfo.timeline,
getCurrentWindowIndex(), getCurrentMediaItemIndex(),
clock, clock,
internalPlayer.getPlaybackLooper()); internalPlayer.getPlaybackLooper());
} }
@ -923,7 +923,10 @@ import java.util.concurrent.CopyOnWriteArraySet;
if (isPlayingAd()) { if (isPlayingAd()) {
playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period); playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period);
return playbackInfo.requestedContentPositionUs == C.TIME_UNSET return playbackInfo.requestedContentPositionUs == C.TIME_UNSET
? playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDefaultPositionMs() ? playbackInfo
.timeline
.getWindow(getCurrentMediaItemIndex(), window)
.getDefaultPositionMs()
: period.getPositionInWindowMs() + Util.usToMs(playbackInfo.requestedContentPositionUs); : period.getPositionInWindowMs() + Util.usToMs(playbackInfo.requestedContentPositionUs);
} else { } else {
return getCurrentPosition(); return getCurrentPosition();
@ -937,7 +940,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
if (playbackInfo.loadingMediaPeriodId.windowSequenceNumber if (playbackInfo.loadingMediaPeriodId.windowSequenceNumber
!= playbackInfo.periodId.windowSequenceNumber) { != playbackInfo.periodId.windowSequenceNumber) {
return playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); return playbackInfo.timeline.getWindow(getCurrentMediaItemIndex(), window).getDurationMs();
} }
long contentBufferedPositionUs = playbackInfo.bufferedPositionUs; long contentBufferedPositionUs = playbackInfo.bufferedPositionUs;
if (playbackInfo.loadingMediaPeriodId.isAd()) { if (playbackInfo.loadingMediaPeriodId.isAd()) {
@ -1231,7 +1234,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
boolean positionDiscontinuity, boolean positionDiscontinuity,
@DiscontinuityReason int positionDiscontinuityReason, @DiscontinuityReason int positionDiscontinuityReason,
long discontinuityWindowStartPositionUs, long discontinuityWindowStartPositionUs,
int oldMaskingWindowIndex) { int oldMaskingMediaItemIndex) {
// Assign playback info immediately such that all getters return the right values, but keep // 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. // snapshot of previous and new state so that listener invocations are triggered correctly.
@ -1280,7 +1283,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
if (positionDiscontinuity) { if (positionDiscontinuity) {
PositionInfo previousPositionInfo = PositionInfo previousPositionInfo =
getPreviousPositionInfo( getPreviousPositionInfo(
positionDiscontinuityReason, previousPlaybackInfo, oldMaskingWindowIndex); positionDiscontinuityReason, previousPlaybackInfo, oldMaskingMediaItemIndex);
PositionInfo positionInfo = getPositionInfo(discontinuityWindowStartPositionUs); PositionInfo positionInfo = getPositionInfo(discontinuityWindowStartPositionUs);
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_POSITION_DISCONTINUITY, Player.EVENT_POSITION_DISCONTINUITY,
@ -1391,19 +1394,19 @@ import java.util.concurrent.CopyOnWriteArraySet;
private PositionInfo getPreviousPositionInfo( private PositionInfo getPreviousPositionInfo(
@DiscontinuityReason int positionDiscontinuityReason, @DiscontinuityReason int positionDiscontinuityReason,
PlaybackInfo oldPlaybackInfo, PlaybackInfo oldPlaybackInfo,
int oldMaskingWindowIndex) { int oldMaskingMediaItemIndex) {
@Nullable Object oldWindowUid = null; @Nullable Object oldWindowUid = null;
@Nullable Object oldPeriodUid = null; @Nullable Object oldPeriodUid = null;
int oldWindowIndex = oldMaskingWindowIndex; int oldMediaItemIndex = oldMaskingMediaItemIndex;
int oldPeriodIndex = C.INDEX_UNSET; int oldPeriodIndex = C.INDEX_UNSET;
@Nullable MediaItem oldMediaItem = null; @Nullable MediaItem oldMediaItem = null;
Timeline.Period oldPeriod = new Timeline.Period(); Timeline.Period oldPeriod = new Timeline.Period();
if (!oldPlaybackInfo.timeline.isEmpty()) { if (!oldPlaybackInfo.timeline.isEmpty()) {
oldPeriodUid = oldPlaybackInfo.periodId.periodUid; oldPeriodUid = oldPlaybackInfo.periodId.periodUid;
oldPlaybackInfo.timeline.getPeriodByUid(oldPeriodUid, oldPeriod); oldPlaybackInfo.timeline.getPeriodByUid(oldPeriodUid, oldPeriod);
oldWindowIndex = oldPeriod.windowIndex; oldMediaItemIndex = oldPeriod.windowIndex;
oldPeriodIndex = oldPlaybackInfo.timeline.getIndexOfPeriod(oldPeriodUid); oldPeriodIndex = oldPlaybackInfo.timeline.getIndexOfPeriod(oldPeriodUid);
oldWindowUid = oldPlaybackInfo.timeline.getWindow(oldWindowIndex, window).uid; oldWindowUid = oldPlaybackInfo.timeline.getWindow(oldMediaItemIndex, window).uid;
oldMediaItem = window.mediaItem; oldMediaItem = window.mediaItem;
} }
long oldPositionUs; long oldPositionUs;
@ -1434,7 +1437,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
return new PositionInfo( return new PositionInfo(
oldWindowUid, oldWindowUid,
oldWindowIndex, oldMediaItemIndex,
oldMediaItem, oldMediaItem,
oldPeriodUid, oldPeriodUid,
oldPeriodIndex, oldPeriodIndex,
@ -1447,20 +1450,20 @@ import java.util.concurrent.CopyOnWriteArraySet;
private PositionInfo getPositionInfo(long discontinuityWindowStartPositionUs) { private PositionInfo getPositionInfo(long discontinuityWindowStartPositionUs) {
@Nullable Object newWindowUid = null; @Nullable Object newWindowUid = null;
@Nullable Object newPeriodUid = null; @Nullable Object newPeriodUid = null;
int newWindowIndex = getCurrentWindowIndex(); int newMediaItemIndex = getCurrentMediaItemIndex();
int newPeriodIndex = C.INDEX_UNSET; int newPeriodIndex = C.INDEX_UNSET;
@Nullable MediaItem newMediaItem = null; @Nullable MediaItem newMediaItem = null;
if (!playbackInfo.timeline.isEmpty()) { if (!playbackInfo.timeline.isEmpty()) {
newPeriodUid = playbackInfo.periodId.periodUid; newPeriodUid = playbackInfo.periodId.periodUid;
playbackInfo.timeline.getPeriodByUid(newPeriodUid, period); playbackInfo.timeline.getPeriodByUid(newPeriodUid, period);
newPeriodIndex = playbackInfo.timeline.getIndexOfPeriod(newPeriodUid); newPeriodIndex = playbackInfo.timeline.getIndexOfPeriod(newPeriodUid);
newWindowUid = playbackInfo.timeline.getWindow(newWindowIndex, window).uid; newWindowUid = playbackInfo.timeline.getWindow(newMediaItemIndex, window).uid;
newMediaItem = window.mediaItem; newMediaItem = window.mediaItem;
} }
long positionMs = Util.usToMs(discontinuityWindowStartPositionUs); long positionMs = Util.usToMs(discontinuityWindowStartPositionUs);
return new PositionInfo( return new PositionInfo(
newWindowUid, newWindowUid,
newWindowIndex, newMediaItemIndex,
newMediaItem, newMediaItem,
newPeriodUid, newPeriodUid,
newPeriodIndex, newPeriodIndex,
@ -1614,7 +1617,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
private PlaybackInfo removeMediaItemsInternal(int fromIndex, int toIndex) { private PlaybackInfo removeMediaItemsInternal(int fromIndex, int toIndex) {
Assertions.checkArgument( Assertions.checkArgument(
fromIndex >= 0 && toIndex >= fromIndex && toIndex <= mediaSourceHolderSnapshots.size()); fromIndex >= 0 && toIndex >= fromIndex && toIndex <= mediaSourceHolderSnapshots.size());
int currentWindowIndex = getCurrentWindowIndex(); int currentIndex = getCurrentMediaItemIndex();
Timeline oldTimeline = getCurrentTimeline(); Timeline oldTimeline = getCurrentTimeline();
int currentMediaSourceCount = mediaSourceHolderSnapshots.size(); int currentMediaSourceCount = mediaSourceHolderSnapshots.size();
pendingOperationAcks++; pendingOperationAcks++;
@ -1631,7 +1634,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
&& newPlaybackInfo.playbackState != STATE_ENDED && newPlaybackInfo.playbackState != STATE_ENDED
&& fromIndex < toIndex && fromIndex < toIndex
&& toIndex == currentMediaSourceCount && toIndex == currentMediaSourceCount
&& currentWindowIndex >= newPlaybackInfo.timeline.getWindowCount(); && currentIndex >= newPlaybackInfo.timeline.getWindowCount();
if (transitionsToEnded) { if (transitionsToEnded) {
newPlaybackInfo = newPlaybackInfo.copyWithPlaybackState(STATE_ENDED); newPlaybackInfo = newPlaybackInfo.copyWithPlaybackState(STATE_ENDED);
} }
@ -1766,11 +1769,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
isCleared ? C.INDEX_UNSET : getCurrentWindowIndexInternal(), isCleared ? C.INDEX_UNSET : getCurrentWindowIndexInternal(),
isCleared ? C.TIME_UNSET : currentPositionMs); isCleared ? C.TIME_UNSET : currentPositionMs);
} }
int currentWindowIndex = getCurrentWindowIndex(); int currentMediaItemIndex = getCurrentMediaItemIndex();
@Nullable @Nullable
Pair<Object, Long> oldPeriodPosition = Pair<Object, Long> oldPeriodPosition =
oldTimeline.getPeriodPosition( oldTimeline.getPeriodPosition(
window, period, currentWindowIndex, Util.msToUs(currentPositionMs)); window, period, currentMediaItemIndex, Util.msToUs(currentPositionMs));
Object periodUid = castNonNull(oldPeriodPosition).first; Object periodUid = castNonNull(oldPeriodPosition).first;
if (newTimeline.getIndexOfPeriod(periodUid) != C.INDEX_UNSET) { if (newTimeline.getIndexOfPeriod(periodUid) != C.INDEX_UNSET) {
// The old period position is still available in the new timeline. // The old period position is still available in the new timeline.

View File

@ -2726,7 +2726,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
newTimeline, newTimeline,
new SeekPosition( new SeekPosition(
pendingMessageInfo.message.getTimeline(), pendingMessageInfo.message.getTimeline(),
pendingMessageInfo.message.getWindowIndex(), pendingMessageInfo.message.getMediaItemIndex(),
requestPositionUs), requestPositionUs),
/* trySubsequentPeriods= */ false, /* trySubsequentPeriods= */ false,
repeatMode, repeatMode,

View File

@ -70,7 +70,7 @@ public final class PlayerMessage {
private int type; private int type;
@Nullable private Object payload; @Nullable private Object payload;
private Looper looper; private Looper looper;
private int windowIndex; private int mediaItemIndex;
private long positionMs; private long positionMs;
private boolean deleteAfterDelivery; private boolean deleteAfterDelivery;
private boolean isSent; private boolean isSent;
@ -85,8 +85,8 @@ public final class PlayerMessage {
* @param target The {@link Target} the message is sent to. * @param target The {@link Target} the message is sent to.
* @param timeline The timeline used when setting the position with {@link #setPosition(long)}. If * @param timeline The timeline used when setting the position with {@link #setPosition(long)}. If
* set to {@link Timeline#EMPTY}, any position can be specified. * set to {@link Timeline#EMPTY}, any position can be specified.
* @param defaultWindowIndex The default window index in the {@code timeline} when no other window * @param defaultMediaItemIndex The default media item index in the {@code timeline} when no other
* index is specified. * media item index is specified.
* @param clock The {@link Clock}. * @param clock The {@link Clock}.
* @param defaultLooper The default {@link Looper} to send the message on when no other looper is * @param defaultLooper The default {@link Looper} to send the message on when no other looper is
* specified. * specified.
@ -95,7 +95,7 @@ public final class PlayerMessage {
Sender sender, Sender sender,
Target target, Target target,
Timeline timeline, Timeline timeline,
int defaultWindowIndex, int defaultMediaItemIndex,
Clock clock, Clock clock,
Looper defaultLooper) { Looper defaultLooper) {
this.sender = sender; this.sender = sender;
@ -103,7 +103,7 @@ public final class PlayerMessage {
this.timeline = timeline; this.timeline = timeline;
this.looper = defaultLooper; this.looper = defaultLooper;
this.clock = clock; this.clock = clock;
this.windowIndex = defaultWindowIndex; this.mediaItemIndex = defaultMediaItemIndex;
this.positionMs = C.TIME_UNSET; this.positionMs = C.TIME_UNSET;
this.deleteAfterDelivery = true; this.deleteAfterDelivery = true;
} }
@ -180,21 +180,21 @@ public final class PlayerMessage {
} }
/** /**
* Returns position in window at {@link #getWindowIndex()} at which the message will be delivered, * Returns position in the media item at {@link #getMediaItemIndex()} at which the message will be
* in milliseconds. If {@link C#TIME_UNSET}, the message will be delivered immediately. If {@link * delivered, in milliseconds. If {@link C#TIME_UNSET}, the message will be delivered immediately.
* C#TIME_END_OF_SOURCE}, the message will be delivered at the end of the window at {@link * If {@link C#TIME_END_OF_SOURCE}, the message will be delivered at the end of the media item at
* #getWindowIndex()}. * {@link #getMediaItemIndex()}.
*/ */
public long getPositionMs() { public long getPositionMs() {
return positionMs; 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 * 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. * @return This message.
* @throws IllegalStateException If {@link #send()} has already been called. * @throws IllegalStateException If {@link #send()} has already been called.
*/ */
@ -205,31 +205,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 mediaItemIndex The index of the media item at which the message will be sent.
* @param positionMs The position in the window with index {@code windowIndex} at which the * @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 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. * @return This message.
* @throws IllegalSeekPositionException If the timeline returned by {@link #getTimeline()} is not * @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. * @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.checkState(!isSent);
Assertions.checkArgument(positionMs != C.TIME_UNSET); Assertions.checkArgument(positionMs != C.TIME_UNSET);
if (windowIndex < 0 || (!timeline.isEmpty() && windowIndex >= timeline.getWindowCount())) { if (mediaItemIndex < 0
throw new IllegalSeekPositionException(timeline, windowIndex, positionMs); || (!timeline.isEmpty() && mediaItemIndex >= timeline.getWindowCount())) {
throw new IllegalSeekPositionException(timeline, mediaItemIndex, positionMs);
} }
this.windowIndex = windowIndex; this.mediaItemIndex = mediaItemIndex;
this.positionMs = positionMs; this.positionMs = positionMs;
return this; return this;
} }
/** Returns window index at which the message will be delivered. */ /** Returns media item index at which the message will be delivered. */
public int getWindowIndex() { public int getMediaItemIndex() {
return windowIndex; return mediaItemIndex;
} }
/** /**

View File

@ -1121,9 +1121,9 @@ public class SimpleExoPlayer extends BasePlayer
@Override @Override
public void setMediaSources( public void setMediaSources(
List<MediaSource> mediaSources, int startWindowIndex, long startPositionMs) { List<MediaSource> mediaSources, int startMediaItemIndex, long startPositionMs) {
verifyApplicationThread(); verifyApplicationThread();
player.setMediaSources(mediaSources, startWindowIndex, startPositionMs); player.setMediaSources(mediaSources, startMediaItemIndex, startPositionMs);
} }
@Override @Override
@ -1430,7 +1430,7 @@ public class SimpleExoPlayer extends BasePlayer
@Override @Override
public int getCurrentMediaItemIndex() { public int getCurrentMediaItemIndex() {
verifyApplicationThread(); verifyApplicationThread();
return player.getCurrentWindowIndex(); return player.getCurrentMediaItemIndex();
} }
@Override @Override

View File

@ -916,7 +916,7 @@ public class AnalyticsCollector
long eventPositionMs; long eventPositionMs;
boolean isInCurrentWindow = boolean isInCurrentWindow =
timeline.equals(player.getCurrentTimeline()) timeline.equals(player.getCurrentTimeline())
&& windowIndex == player.getCurrentWindowIndex(); && windowIndex == player.getCurrentMediaItemIndex();
if (mediaPeriodId != null && mediaPeriodId.isAd()) { if (mediaPeriodId != null && mediaPeriodId.isAd()) {
boolean isCurrentAd = boolean isCurrentAd =
isInCurrentWindow isInCurrentWindow
@ -941,7 +941,7 @@ public class AnalyticsCollector
mediaPeriodId, mediaPeriodId,
eventPositionMs, eventPositionMs,
player.getCurrentTimeline(), player.getCurrentTimeline(),
player.getCurrentWindowIndex(), player.getCurrentMediaItemIndex(),
currentMediaPeriodId, currentMediaPeriodId,
player.getCurrentPosition(), player.getCurrentPosition(),
player.getTotalBufferedDuration()); player.getTotalBufferedDuration());
@ -964,7 +964,7 @@ public class AnalyticsCollector
? null ? null
: mediaPeriodQueueTracker.getMediaPeriodIdTimeline(mediaPeriodId); : mediaPeriodQueueTracker.getMediaPeriodIdTimeline(mediaPeriodId);
if (mediaPeriodId == null || knownTimeline == null) { if (mediaPeriodId == null || knownTimeline == null) {
int windowIndex = player.getCurrentWindowIndex(); int windowIndex = player.getCurrentMediaItemIndex();
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
boolean windowIsInTimeline = windowIndex < timeline.getWindowCount(); boolean windowIsInTimeline = windowIndex < timeline.getWindowCount();
return generateEventTime( return generateEventTime(

View File

@ -384,7 +384,7 @@ public interface AnalyticsListener {
/** /**
* The current window index in {@link #currentTimeline} at the time of the event, or the * 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 * prospective window index if the timeline is not yet known and empty (equivalent to {@link
* Player#getCurrentWindowIndex()}). * Player#getCurrentMediaItemIndex()}).
*/ */
public final int currentWindowIndex; public final int currentWindowIndex;
@ -421,7 +421,7 @@ public interface AnalyticsListener {
* {@link Player#getCurrentTimeline()}). * {@link Player#getCurrentTimeline()}).
* @param currentWindowIndex The current window index in {@code currentTimeline} at the time of * @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 * 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 * @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 * playing media period at the time of the event, or {@code null} if no current media period
* identifier is available. * identifier is available.
@ -1206,9 +1206,9 @@ public interface AnalyticsListener {
* {@link Player#seekTo(long)} after a {@link * {@link Player#seekTo(long)} after a {@link
* AnalyticsListener#onMediaItemTransition(EventTime, MediaItem, int)}). * AnalyticsListener#onMediaItemTransition(EventTime, MediaItem, int)}).
* <li>They intend to use multiple state values together or in combination with {@link Player} * <li>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 * getter methods. For example using {@link Player#getCurrentMediaItemIndex()} with the
* timeline} provided in {@link #onTimelineChanged(EventTime, int)} is only safe from within * {@code timeline} provided in {@link #onTimelineChanged(EventTime, int)} is only safe from
* this method. * within this method.
* <li>They are interested in events that logically happened together (e.g {@link * <li>They are interested in events that logically happened together (e.g {@link
* #onPlaybackStateChanged(EventTime, int)} to {@link Player#STATE_BUFFERING} because of * #onPlaybackStateChanged(EventTime, int)} to {@link Player#STATE_BUFFERING} because of
* {@link #onMediaItemTransition(EventTime, MediaItem, int)}). * {@link #onMediaItemTransition(EventTime, MediaItem, int)}).

View File

@ -141,8 +141,8 @@ public class DebugTextViewHelper implements Player.Listener, Runnable {
break; break;
} }
return String.format( return String.format(
"playWhenReady:%s playbackState:%s window:%s", "playWhenReady:%s playbackState:%s item:%s",
player.getPlayWhenReady(), playbackStateString, player.getCurrentWindowIndex()); player.getPlayWhenReady(), playbackStateString, player.getCurrentMediaItemIndex());
} }
/** Returns a string containing video debugging information. */ /** Returns a string containing video debugging information. */

View File

@ -279,7 +279,7 @@ import androidx.media3.test.utils.StubExoPlayer;
timeline.getPeriod(0, period).getAdDurationUs(adGroupIndex, adIndexInAdGroup); timeline.getPeriod(0, period).getAdDurationUs(adGroupIndex, adIndexInAdGroup);
return Util.usToMs(adDurationUs); return Util.usToMs(adDurationUs);
} else { } else {
return timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); return timeline.getWindow(getCurrentMediaItemIndex(), window).getDurationMs();
} }
} }

View File

@ -1238,7 +1238,7 @@ public class MediaController implements Player {
Timeline timeline = getCurrentTimeline(); Timeline timeline = getCurrentTimeline();
return timeline.isEmpty() return timeline.isEmpty()
? null ? null
: timeline.getWindow(getCurrentWindowIndex(), window).mediaItem; : timeline.getWindow(getCurrentMediaItemIndex(), window).mediaItem;
} }
@Override @Override

View File

@ -607,9 +607,9 @@ public class PlayerNotificationManager {
public static final String ACTION_PLAY = "androidx.media3.ui.notification.play"; public static final String ACTION_PLAY = "androidx.media3.ui.notification.play";
/** The action which pauses playback. */ /** The action which pauses playback. */
public static final String ACTION_PAUSE = "androidx.media3.ui.notification.pause"; public static final String ACTION_PAUSE = "androidx.media3.ui.notification.pause";
/** The action which skips to the previous window. */ /** The action which skips to the previous media item. */
public static final String ACTION_PREVIOUS = "androidx.media3.ui.notification.prev"; public static final String ACTION_PREVIOUS = "androidx.media3.ui.notification.prev";
/** The action which skips to the next window. */ /** The action which skips to the next media item. */
public static final String ACTION_NEXT = "androidx.media3.ui.notification.next"; public static final String ACTION_NEXT = "androidx.media3.ui.notification.next";
/** The action which fast forwards. */ /** The action which fast forwards. */
public static final String ACTION_FAST_FORWARD = "androidx.media3.ui.notification.ffwd"; public static final String ACTION_FAST_FORWARD = "androidx.media3.ui.notification.ffwd";
@ -1097,7 +1097,7 @@ public class PlayerNotificationManager {
* *
* <ul> * <ul>
* <li>The media is {@link Player#isPlaying() actively playing}. * <li>The media is {@link Player#isPlaying() actively playing}.
* <li>The media is not {@link Player#isCurrentWindowDynamic() dynamically changing its * <li>The media is not {@link Player#isCurrentMediaItemDynamic() dynamically changing its
* duration} (like for example a live stream). * duration} (like for example a live stream).
* <li>The media is not {@link Player#isPlayingAd() interrupted by an ad}. * <li>The media is not {@link Player#isPlayingAd() interrupted by an ad}.
* <li>The media is played at {@link Player#getPlaybackParameters() regular speed}. * <li>The media is played at {@link Player#getPlaybackParameters() regular speed}.
@ -1255,7 +1255,7 @@ public class PlayerNotificationManager {
&& useChronometer && useChronometer
&& player.isPlaying() && player.isPlaying()
&& !player.isPlayingAd() && !player.isPlayingAd()
&& !player.isCurrentWindowDynamic() && !player.isCurrentMediaItemDynamic()
&& player.getPlaybackParameters().speed == 1f) { && player.getPlaybackParameters().speed == 1f) {
builder builder
.setWhen(System.currentTimeMillis() - player.getContentPosition()) .setWhen(System.currentTimeMillis() - player.getContentPosition())
@ -1533,7 +1533,7 @@ public class PlayerNotificationManager {
if (player.getPlaybackState() == Player.STATE_IDLE) { if (player.getPlaybackState() == Player.STATE_IDLE) {
player.prepare(); player.prepare();
} else if (player.getPlaybackState() == Player.STATE_ENDED) { } else if (player.getPlaybackState() == Player.STATE_ENDED) {
player.seekToDefaultPosition(player.getCurrentWindowIndex()); player.seekToDefaultPosition(player.getCurrentMediaItemIndex());
} }
player.play(); player.play();
} else if (ACTION_PAUSE.equals(action)) { } else if (ACTION_PAUSE.equals(action)) {

View File

@ -728,7 +728,7 @@ import java.util.List;
| PlaybackStateCompat.ACTION_SET_REPEAT_MODE | PlaybackStateCompat.ACTION_SET_REPEAT_MODE
| PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE | PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE
| PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED; | PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED;
long queueItemId = MediaUtils.convertToQueueItemId(getCurrentWindowIndex()); long queueItemId = MediaUtils.convertToQueueItemId(getCurrentMediaItemIndex());
PlaybackStateCompat.Builder builder = PlaybackStateCompat.Builder builder =
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setState( .setState(
@ -807,7 +807,7 @@ import java.util.List;
public PositionInfo createPositionInfoForBundling() { public PositionInfo createPositionInfoForBundling() {
return new PositionInfo( return new PositionInfo(
/* windowUid= */ null, /* windowUid= */ null,
getCurrentWindowIndex(), getCurrentMediaItemIndex(),
/* periodUid= */ null, /* periodUid= */ null,
getCurrentMediaItem(), getCurrentMediaItem(),
getCurrentPeriodIndex(), getCurrentPeriodIndex(),

View File

@ -73,7 +73,7 @@ public class PlayerWrapperTest {
when(player.getContentDuration()).thenReturn(testContentDurationMs); when(player.getContentDuration()).thenReturn(testContentDurationMs);
when(player.getContentPosition()).thenReturn(testContentPositionMs); when(player.getContentPosition()).thenReturn(testContentPositionMs);
when(player.getContentBufferedPosition()).thenReturn(testContentBufferedPositionMs); when(player.getContentBufferedPosition()).thenReturn(testContentBufferedPositionMs);
when(player.getCurrentWindowIndex()).thenReturn(testmediaItemIndex); when(player.getCurrentMediaItemIndex()).thenReturn(testmediaItemIndex);
when(player.getCurrentPeriodIndex()).thenReturn(testPeriodIndex); when(player.getCurrentPeriodIndex()).thenReturn(testPeriodIndex);
SessionPositionInfo sessionPositionInfo = playerWrapper.createSessionPositionInfoForBundling(); SessionPositionInfo sessionPositionInfo = playerWrapper.createSessionPositionInfoForBundling();

View File

@ -392,7 +392,7 @@ public class MediaControllerListenerTest {
boolean testIsPlayingAd = true; boolean testIsPlayingAd = true;
int testCurrentAdGroupIndex = 2; int testCurrentAdGroupIndex = 2;
int testCurrentAdIndexInAdGroup = 6; int testCurrentAdIndexInAdGroup = 6;
int testWindowIndex = 1; int testMediaItemIndex = 1;
int testPeriodIndex = 2; int testPeriodIndex = 2;
controller = controllerTestRule.createController(remoteSession.getToken()); controller = controllerTestRule.createController(remoteSession.getToken());
@ -410,7 +410,7 @@ public class MediaControllerListenerTest {
AtomicBoolean isPlayingAdRef = new AtomicBoolean(); AtomicBoolean isPlayingAdRef = new AtomicBoolean();
AtomicInteger currentAdGroupIndexRef = new AtomicInteger(); AtomicInteger currentAdGroupIndexRef = new AtomicInteger();
AtomicInteger currentAdIndexInAdGroupRef = new AtomicInteger(); AtomicInteger currentAdIndexInAdGroupRef = new AtomicInteger();
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
AtomicInteger currentPeriodIndexRef = new AtomicInteger(); AtomicInteger currentPeriodIndexRef = new AtomicInteger();
threadTestRule threadTestRule
.getHandler() .getHandler()
@ -435,7 +435,7 @@ public class MediaControllerListenerTest {
isPlayingAdRef.set(controller.isPlayingAd()); isPlayingAdRef.set(controller.isPlayingAd());
currentAdGroupIndexRef.set(controller.getCurrentAdGroupIndex()); currentAdGroupIndexRef.set(controller.getCurrentAdGroupIndex());
currentAdIndexInAdGroupRef.set(controller.getCurrentAdIndexInAdGroup()); currentAdIndexInAdGroupRef.set(controller.getCurrentAdIndexInAdGroup());
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
currentPeriodIndexRef.set(controller.getCurrentPeriodIndex()); currentPeriodIndexRef.set(controller.getCurrentPeriodIndex());
latch.countDown(); latch.countDown();
} }
@ -455,7 +455,7 @@ public class MediaControllerListenerTest {
.setIsPlayingAd(testIsPlayingAd) .setIsPlayingAd(testIsPlayingAd)
.setCurrentAdGroupIndex(testCurrentAdGroupIndex) .setCurrentAdGroupIndex(testCurrentAdGroupIndex)
.setCurrentAdIndexInAdGroup(testCurrentAdIndexInAdGroup) .setCurrentAdIndexInAdGroup(testCurrentAdIndexInAdGroup)
.setCurrentMediaItemIndex(testWindowIndex) .setCurrentMediaItemIndex(testMediaItemIndex)
.setCurrentPeriodIndex(testPeriodIndex) .setCurrentPeriodIndex(testPeriodIndex)
.build(); .build();
remoteSession.setPlayer(playerConfig); remoteSession.setPlayer(playerConfig);
@ -473,7 +473,7 @@ public class MediaControllerListenerTest {
assertThat(isPlayingAdRef.get()).isEqualTo(testIsPlayingAd); assertThat(isPlayingAdRef.get()).isEqualTo(testIsPlayingAd);
assertThat(currentAdGroupIndexRef.get()).isEqualTo(testCurrentAdGroupIndex); assertThat(currentAdGroupIndexRef.get()).isEqualTo(testCurrentAdGroupIndex);
assertThat(currentAdIndexInAdGroupRef.get()).isEqualTo(testCurrentAdIndexInAdGroup); assertThat(currentAdIndexInAdGroupRef.get()).isEqualTo(testCurrentAdIndexInAdGroup);
assertThat(currentWindowIndexRef.get()).isEqualTo(testWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testMediaItemIndex);
assertThat(currentPeriodIndexRef.get()).isEqualTo(testPeriodIndex); assertThat(currentPeriodIndexRef.get()).isEqualTo(testPeriodIndex);
} }
@ -836,8 +836,8 @@ public class MediaControllerListenerTest {
public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) { public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
shuffleModeEnabledFromParamRef.set(shuffleModeEnabled); shuffleModeEnabledFromParamRef.set(shuffleModeEnabled);
shuffleModeEnabledFromGetterRef.set(controller.getShuffleModeEnabled()); shuffleModeEnabledFromGetterRef.set(controller.getShuffleModeEnabled());
previousIndexRef.set(controller.getPreviousWindowIndex()); previousIndexRef.set(controller.getPreviousMediaItemIndex());
nextIndexRef.set(controller.getNextWindowIndex()); nextIndexRef.set(controller.getNextMediaItemIndex());
latch.countDown(); latch.countDown();
} }
}; };
@ -876,8 +876,8 @@ public class MediaControllerListenerTest {
public void onRepeatModeChanged(@RepeatMode int repeatMode) { public void onRepeatModeChanged(@RepeatMode int repeatMode) {
repeatModeFromParamRef.set(repeatMode); repeatModeFromParamRef.set(repeatMode);
repeatModeFromGetterRef.set(controller.getRepeatMode()); repeatModeFromGetterRef.set(controller.getRepeatMode());
previousIndexRef.set(controller.getPreviousWindowIndex()); previousIndexRef.set(controller.getPreviousMediaItemIndex());
nextIndexRef.set(controller.getNextWindowIndex()); nextIndexRef.set(controller.getNextMediaItemIndex());
latch.countDown(); latch.countDown();
} }
}; };
@ -1352,7 +1352,7 @@ public class MediaControllerListenerTest {
PositionInfo testOldPosition = PositionInfo testOldPosition =
new PositionInfo( new PositionInfo(
/* windowUid= */ null, /* windowUid= */ null,
/* windowIndex= */ 2, /* mediaItemIndex= */ 2,
new MediaItem.Builder().setMediaId("media-id-2").build(), new MediaItem.Builder().setMediaId("media-id-2").build(),
/* periodUid= */ null, /* periodUid= */ null,
/* periodIndex= */ C.INDEX_UNSET, /* periodIndex= */ C.INDEX_UNSET,
@ -1363,7 +1363,7 @@ public class MediaControllerListenerTest {
PositionInfo testNewPosition = PositionInfo testNewPosition =
new PositionInfo( new PositionInfo(
/* windowUid= */ null, /* windowUid= */ null,
/* windowIndex= */ 3, /* mediaItemIndex= */ 3,
new MediaItem.Builder().setMediaId("media-id-3").build(), new MediaItem.Builder().setMediaId("media-id-3").build(),
/* periodUid= */ null, /* periodUid= */ null,
/* periodIndex= */ C.INDEX_UNSET, /* periodIndex= */ C.INDEX_UNSET,
@ -1418,7 +1418,7 @@ public class MediaControllerListenerTest {
PositionInfo newPositionInfo = PositionInfo newPositionInfo =
new PositionInfo( new PositionInfo(
/* windowUid= */ null, /* windowUid= */ null,
/* windowIndex= */ C.INDEX_UNSET, /* mediaItemIndex= */ C.INDEX_UNSET,
/* mediaItem= */ null, /* mediaItem= */ null,
/* periodUid= */ null, /* periodUid= */ null,
/* periodIndex= */ C.INDEX_UNSET, /* periodIndex= */ C.INDEX_UNSET,

View File

@ -188,7 +188,7 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
threadTestRule.getHandler().postAndSync(controller::getCurrentTimeline); threadTestRule.getHandler().postAndSync(controller::getCurrentTimeline);
assertThat(currentTimeline).isEqualTo(timelineRef.get()); assertThat(currentTimeline).isEqualTo(timelineRef.get());
int currentMediaItemIndex = int currentMediaItemIndex =
threadTestRule.getHandler().postAndSync(controller::getCurrentWindowIndex); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItemIndex);
assertThat(currentMediaItemIndex).isEqualTo(testMediaItemIndex); assertThat(currentMediaItemIndex).isEqualTo(testMediaItemIndex);
MediaItem currentMediaItem = MediaItem currentMediaItem =
threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem);
@ -292,7 +292,7 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
threadTestRule.getHandler().postAndSync(controller::getCurrentTimeline); threadTestRule.getHandler().postAndSync(controller::getCurrentTimeline);
assertThat(currentTimeline).isEqualTo(timelineRef.get()); assertThat(currentTimeline).isEqualTo(timelineRef.get());
int currentMediaItemIndex = int currentMediaItemIndex =
threadTestRule.getHandler().postAndSync(controller::getCurrentWindowIndex); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItemIndex);
assertThat(currentMediaItemIndex).isEqualTo(testMediaItemIndex); assertThat(currentMediaItemIndex).isEqualTo(testMediaItemIndex);
MediaItem currentMediaItem = MediaItem currentMediaItem =
threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem);
@ -384,7 +384,7 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
threadTestRule.getHandler().postAndSync(controller::getCurrentTimeline); threadTestRule.getHandler().postAndSync(controller::getCurrentTimeline);
assertThat(currentTimeline).isEqualTo(timelineRef.get()); assertThat(currentTimeline).isEqualTo(timelineRef.get());
int currentMediaItemIndex = int currentMediaItemIndex =
threadTestRule.getHandler().postAndSync(controller::getCurrentWindowIndex); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItemIndex);
assertThat(currentMediaItemIndex).isEqualTo(testMediaItemIndex); assertThat(currentMediaItemIndex).isEqualTo(testMediaItemIndex);
MediaItem currentMediaItem = MediaItem currentMediaItem =
threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem);
@ -483,7 +483,7 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
threadTestRule.getHandler().postAndSync(controller::getCurrentTimeline); threadTestRule.getHandler().postAndSync(controller::getCurrentTimeline);
assertThat(currentTimeline).isEqualTo(timelineRef.get()); assertThat(currentTimeline).isEqualTo(timelineRef.get());
int currentMediaItemIndex = int currentMediaItemIndex =
threadTestRule.getHandler().postAndSync(controller::getCurrentWindowIndex); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItemIndex);
assertThat(currentMediaItemIndex).isEqualTo(testMediaItemIndex); assertThat(currentMediaItemIndex).isEqualTo(testMediaItemIndex);
MediaItem currentMediaItem = MediaItem currentMediaItem =
threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItem);

View File

@ -416,7 +416,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
} }
@Test @Test
public void seekTo_withNewWindowIndex() throws Exception { public void seekTo_withNewMediaItemIndex() throws Exception {
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(3); List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(3);
List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems); List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems);
long initialPosition = 8_000; long initialPosition = 8_000;
@ -543,7 +543,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
} }
@Test @Test
public void seekTo_seekBackwardWithinSameWindow_resetsBufferedPosition() throws Exception { public void seekTo_seekBackwardWithinSameMediaItem_resetsBufferedPosition() throws Exception {
long initialPosition = 8_000L; long initialPosition = 8_000L;
long initialBufferedPosition = 9_200L; long initialBufferedPosition = 9_200L;
int initialIndex = 0; int initialIndex = 0;
@ -621,7 +621,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
} }
@Test @Test
public void seekTo_seekForwardWithinSameWindow_keepsTheBufferedPosition() throws Exception { public void seekTo_seekForwardWithinSameMediaItem_keepsTheBufferedPosition() throws Exception {
long initialPosition = 8_000L; long initialPosition = 8_000L;
long initialBufferedPosition = 9_200L; long initialBufferedPosition = 9_200L;
int initialIndex = 0; int initialIndex = 0;
@ -703,12 +703,12 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems("a", "b", "c"); List<MediaItem> mediaItems = MediaTestUtils.createMediaItems("a", "b", "c");
List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems); List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems);
long testPosition = 200L; long testPosition = 200L;
int testCurrentWindowIndex = 1; int testCurrentMediaItemIndex = 1;
MediaItem testCurrentMediaItem = mediaItems.get(testCurrentWindowIndex); MediaItem testCurrentMediaItem = mediaItems.get(testCurrentMediaItemIndex);
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f) .setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f)
.setActiveQueueItemId(queue.get(testCurrentWindowIndex).getQueueId()) .setActiveQueueItemId(queue.get(testCurrentMediaItemIndex).getQueueId())
.build()); .build());
session.setQueue(queue); session.setQueue(queue);
List<MediaItem> newMediaItems = MediaTestUtils.createMediaItems("A", "B"); List<MediaItem> newMediaItems = MediaTestUtils.createMediaItems("A", "B");
@ -741,7 +741,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>(); AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>();
AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>(); AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>();
threadTestRule threadTestRule
@ -749,7 +749,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
.postAndSync( .postAndSync(
() -> { () -> {
controller.addMediaItems(testAddIndex, newMediaItems); controller.addMediaItems(testAddIndex, newMediaItems);
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
currentMediaItemRef.set(controller.getCurrentMediaItem()); currentMediaItemRef.set(controller.getCurrentMediaItem());
timelineFromGetterRef.set(controller.getCurrentTimeline()); timelineFromGetterRef.set(controller.getCurrentTimeline());
}); });
@ -758,22 +758,23 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems);
assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED); assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
assertThat(onEventsRef.get()).isEqualTo(testEvents); assertThat(onEventsRef.get()).isEqualTo(testEvents);
assertThat(currentWindowIndexRef.get()).isEqualTo(testCurrentWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testCurrentMediaItemIndex);
assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem); assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem);
MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems);
} }
@Test @Test
public void addMediaItems_beforeCurrentWindowIndex_shiftsCurrentWindowIndex() throws Exception { public void addMediaItems_beforeCurrentMediaItemIndex_shiftsCurrentMediaItemIndex()
throws Exception {
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems("a", "b", "c"); List<MediaItem> mediaItems = MediaTestUtils.createMediaItems("a", "b", "c");
List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems); List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems);
long testPosition = 200L; long testPosition = 200L;
int initialWindowIndex = 2; int initialMediaItemIndex = 2;
MediaItem testCurrentMediaItem = mediaItems.get(initialWindowIndex); MediaItem testCurrentMediaItem = mediaItems.get(initialMediaItemIndex);
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f) .setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f)
.setActiveQueueItemId(queue.get(initialWindowIndex).getQueueId()) .setActiveQueueItemId(queue.get(initialMediaItemIndex).getQueueId())
.build()); .build());
session.setQueue(queue); session.setQueue(queue);
List<MediaItem> newMediaItems = MediaTestUtils.createMediaItems("A", "B"); List<MediaItem> newMediaItems = MediaTestUtils.createMediaItems("A", "B");
@ -781,7 +782,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
List<MediaItem> testMediaItems = new ArrayList<>(); List<MediaItem> testMediaItems = new ArrayList<>();
testMediaItems.addAll(mediaItems); testMediaItems.addAll(mediaItems);
testMediaItems.addAll(testAddIndex, newMediaItems); testMediaItems.addAll(testAddIndex, newMediaItems);
int testCurrentWindowIndex = testMediaItems.indexOf(testCurrentMediaItem); int testCurrentMediaItemIndex = testMediaItems.indexOf(testCurrentMediaItem);
Events testEvents = new Events(new FlagSet.Builder().addAll(EVENT_TIMELINE_CHANGED).build()); Events testEvents = new Events(new FlagSet.Builder().addAll(EVENT_TIMELINE_CHANGED).build());
MediaController controller = controllerTestRule.createController(session.getSessionToken()); MediaController controller = controllerTestRule.createController(session.getSessionToken());
@ -807,7 +808,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>(); AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>();
AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>(); AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>();
threadTestRule threadTestRule
@ -815,7 +816,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
.postAndSync( .postAndSync(
() -> { () -> {
controller.addMediaItems(testAddIndex, newMediaItems); controller.addMediaItems(testAddIndex, newMediaItems);
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
currentMediaItemRef.set(controller.getCurrentMediaItem()); currentMediaItemRef.set(controller.getCurrentMediaItem());
timelineFromGetterRef.set(controller.getCurrentTimeline()); timelineFromGetterRef.set(controller.getCurrentTimeline());
}); });
@ -824,7 +825,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems);
assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED); assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
assertThat(onEventsRef.get()).isEqualTo(testEvents); assertThat(onEventsRef.get()).isEqualTo(testEvents);
assertThat(currentWindowIndexRef.get()).isEqualTo(testCurrentWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testCurrentMediaItemIndex);
assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem); assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem);
MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems);
} }
@ -834,12 +835,12 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5); List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5);
List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems); List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems);
long testPosition = 200L; long testPosition = 200L;
int testCurrentWindowIndex = 0; int testCurrentMediaItemIndex = 0;
MediaItem testCurrentMediaItem = mediaItems.get(testCurrentWindowIndex); MediaItem testCurrentMediaItem = mediaItems.get(testCurrentMediaItemIndex);
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f) .setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f)
.setActiveQueueItemId(queue.get(testCurrentWindowIndex).getQueueId()) .setActiveQueueItemId(queue.get(testCurrentMediaItemIndex).getQueueId())
.build()); .build());
session.setQueue(queue); session.setQueue(queue);
int fromIndex = 1; int fromIndex = 1;
@ -871,7 +872,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>(); AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>();
AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>(); AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>();
threadTestRule threadTestRule
@ -879,7 +880,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
.postAndSync( .postAndSync(
() -> { () -> {
controller.removeMediaItems(fromIndex, toIndex); controller.removeMediaItems(fromIndex, toIndex);
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
currentMediaItemRef.set(controller.getCurrentMediaItem()); currentMediaItemRef.set(controller.getCurrentMediaItem());
timelineFromGetterRef.set(controller.getCurrentTimeline()); timelineFromGetterRef.set(controller.getCurrentTimeline());
}); });
@ -888,30 +889,30 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems);
assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED); assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
assertThat(onEventsRef.get()).isEqualTo(testEvents); assertThat(onEventsRef.get()).isEqualTo(testEvents);
assertThat(currentWindowIndexRef.get()).isEqualTo(testCurrentWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testCurrentMediaItemIndex);
assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem); assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem);
MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems);
} }
@Test @Test
public void removeMediaItems_beforeCurrentWindowIndex_shiftsCurrentWindowIndex() public void removeMediaItems_beforeCurrentMediaItemIndex_shiftsCurrentMediaItemIndex()
throws Exception { throws Exception {
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5); List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5);
List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems); List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems);
long testPosition = 200L; long testPosition = 200L;
int initialWindowIndex = 4; int initialMediaItemIndex = 4;
MediaItem testCurrentMediaItem = mediaItems.get(initialWindowIndex); MediaItem testCurrentMediaItem = mediaItems.get(initialMediaItemIndex);
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f) .setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f)
.setActiveQueueItemId(queue.get(initialWindowIndex).getQueueId()) .setActiveQueueItemId(queue.get(initialMediaItemIndex).getQueueId())
.build()); .build());
session.setQueue(queue); session.setQueue(queue);
int testFromIndex = 1; int testFromIndex = 1;
int testToIndex = 3; int testToIndex = 3;
List<MediaItem> testMediaItems = new ArrayList<>(mediaItems.subList(0, testFromIndex)); List<MediaItem> testMediaItems = new ArrayList<>(mediaItems.subList(0, testFromIndex));
testMediaItems.addAll(mediaItems.subList(testToIndex, mediaItems.size())); testMediaItems.addAll(mediaItems.subList(testToIndex, mediaItems.size()));
int testCurrentWindowIndex = testMediaItems.indexOf(testCurrentMediaItem); int testCurrentMediaItemIndex = testMediaItems.indexOf(testCurrentMediaItem);
Events testEvents = new Events(new FlagSet.Builder().addAll(EVENT_TIMELINE_CHANGED).build()); Events testEvents = new Events(new FlagSet.Builder().addAll(EVENT_TIMELINE_CHANGED).build());
MediaController controller = controllerTestRule.createController(session.getSessionToken()); MediaController controller = controllerTestRule.createController(session.getSessionToken());
@ -937,7 +938,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>(); AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>();
AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>(); AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>();
threadTestRule threadTestRule
@ -945,7 +946,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
.postAndSync( .postAndSync(
() -> { () -> {
controller.removeMediaItems(testFromIndex, testToIndex); controller.removeMediaItems(testFromIndex, testToIndex);
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
currentMediaItemRef.set(controller.getCurrentMediaItem()); currentMediaItemRef.set(controller.getCurrentMediaItem());
timelineFromGetterRef.set(controller.getCurrentTimeline()); timelineFromGetterRef.set(controller.getCurrentTimeline());
}); });
@ -954,7 +955,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems);
assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED); assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
assertThat(onEventsRef.get()).isEqualTo(testEvents); assertThat(onEventsRef.get()).isEqualTo(testEvents);
assertThat(currentWindowIndexRef.get()).isEqualTo(testCurrentWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testCurrentMediaItemIndex);
assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem); assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem);
MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems);
} }
@ -964,19 +965,19 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5); List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5);
List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems); List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems);
long testPosition = 200L; long testPosition = 200L;
int initialWindowIndex = 2; int initialMediaItemIndex = 2;
MediaItem testCurrentMediaItem = mediaItems.get(initialWindowIndex); MediaItem testCurrentMediaItem = mediaItems.get(initialMediaItemIndex);
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f) .setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f)
.setActiveQueueItemId(queue.get(initialWindowIndex).getQueueId()) .setActiveQueueItemId(queue.get(initialMediaItemIndex).getQueueId())
.build()); .build());
session.setQueue(queue); session.setQueue(queue);
int testFromIndex = 1; int testFromIndex = 1;
int testToIndex = 3; int testToIndex = 3;
List<MediaItem> testMediaItems = new ArrayList<>(mediaItems.subList(0, testFromIndex)); List<MediaItem> testMediaItems = new ArrayList<>(mediaItems.subList(0, testFromIndex));
testMediaItems.addAll(mediaItems.subList(testToIndex, mediaItems.size())); testMediaItems.addAll(mediaItems.subList(testToIndex, mediaItems.size()));
int testCurrentWindowIndex = testFromIndex; int testCurrentMediaItemIndex = testFromIndex;
Events testEvents = new Events(new FlagSet.Builder().addAll(EVENT_TIMELINE_CHANGED).build()); Events testEvents = new Events(new FlagSet.Builder().addAll(EVENT_TIMELINE_CHANGED).build());
MediaController controller = controllerTestRule.createController(session.getSessionToken()); MediaController controller = controllerTestRule.createController(session.getSessionToken());
@ -1002,14 +1003,14 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>(); AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>();
threadTestRule threadTestRule
.getHandler() .getHandler()
.postAndSync( .postAndSync(
() -> { () -> {
controller.removeMediaItems(testFromIndex, testToIndex); controller.removeMediaItems(testFromIndex, testToIndex);
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
timelineFromGetterRef.set(controller.getCurrentTimeline()); timelineFromGetterRef.set(controller.getCurrentTimeline());
}); });
@ -1017,7 +1018,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems);
assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED); assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
assertThat(onEventsRef.get()).isEqualTo(testEvents); assertThat(onEventsRef.get()).isEqualTo(testEvents);
assertThat(currentWindowIndexRef.get()).isEqualTo(testCurrentWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testCurrentMediaItemIndex);
MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems);
} }
@ -1026,12 +1027,12 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5); List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5);
List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems); List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems);
long testPosition = 200L; long testPosition = 200L;
int testCurrentWindowIndex = 0; int testCurrentMediaItemIndex = 0;
MediaItem testCurrentMediaItem = mediaItems.get(testCurrentWindowIndex); MediaItem testCurrentMediaItem = mediaItems.get(testCurrentMediaItemIndex);
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f) .setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f)
.setActiveQueueItemId(queue.get(testCurrentWindowIndex).getQueueId()) .setActiveQueueItemId(queue.get(testCurrentMediaItemIndex).getQueueId())
.build()); .build());
session.setQueue(queue); session.setQueue(queue);
int testFromIndex = 1; int testFromIndex = 1;
@ -1064,7 +1065,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>(); AtomicReference<MediaItem> currentMediaItemRef = new AtomicReference<>();
AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>(); AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>();
threadTestRule threadTestRule
@ -1072,7 +1073,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
.postAndSync( .postAndSync(
() -> { () -> {
controller.moveMediaItems(testFromIndex, testToIndex, testNewIndex); controller.moveMediaItems(testFromIndex, testToIndex, testNewIndex);
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
currentMediaItemRef.set(controller.getCurrentMediaItem()); currentMediaItemRef.set(controller.getCurrentMediaItem());
timelineFromGetterRef.set(controller.getCurrentTimeline()); timelineFromGetterRef.set(controller.getCurrentTimeline());
}); });
@ -1081,7 +1082,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems);
assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED); assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
assertThat(onEventsRef.get()).isEqualTo(testEvents); assertThat(onEventsRef.get()).isEqualTo(testEvents);
assertThat(currentWindowIndexRef.get()).isEqualTo(testCurrentWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testCurrentMediaItemIndex);
assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem); assertThat(currentMediaItemRef.get()).isEqualTo(testCurrentMediaItem);
MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems);
} }
@ -1091,11 +1092,11 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5); List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(5);
List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems); List<QueueItem> queue = MediaUtils.convertToQueueItemList(mediaItems);
long testPosition = 200L; long testPosition = 200L;
int initialCurrentWindowIndex = 1; int initialCurrentMediaItemIndex = 1;
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f) .setState(PlaybackStateCompat.STATE_PAUSED, testPosition, /* playbackSpeed= */ 1.0f)
.setActiveQueueItemId(queue.get(initialCurrentWindowIndex).getQueueId()) .setActiveQueueItemId(queue.get(initialCurrentMediaItemIndex).getQueueId())
.build()); .build());
session.setQueue(queue); session.setQueue(queue);
int testFromIndex = 1; int testFromIndex = 1;
@ -1106,7 +1107,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
Events testEvents = new Events(new FlagSet.Builder().addAll(EVENT_TIMELINE_CHANGED).build()); Events testEvents = new Events(new FlagSet.Builder().addAll(EVENT_TIMELINE_CHANGED).build());
// The item at testToIndex becomes current media item after removed, // The item at testToIndex becomes current media item after removed,
// and it remains as current media item when removed items are inserted back. // and it remains as current media item when removed items are inserted back.
int testCurrentWindowIndex = testMediaItems.indexOf(mediaItems.get(testToIndex)); int testCurrentMediaItemIndex = testMediaItems.indexOf(mediaItems.get(testToIndex));
MediaController controller = controllerTestRule.createController(session.getSessionToken()); MediaController controller = controllerTestRule.createController(session.getSessionToken());
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
@ -1131,14 +1132,14 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>(); AtomicReference<Timeline> timelineFromGetterRef = new AtomicReference<>();
threadTestRule threadTestRule
.getHandler() .getHandler()
.postAndSync( .postAndSync(
() -> { () -> {
controller.moveMediaItems(testFromIndex, testToIndex, testNewIndex); controller.moveMediaItems(testFromIndex, testToIndex, testNewIndex);
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
timelineFromGetterRef.set(controller.getCurrentTimeline()); timelineFromGetterRef.set(controller.getCurrentTimeline());
}); });
@ -1146,7 +1147,7 @@ public class MediaControllerStateMaskingWithMediaSessionCompatTest {
MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromParamRef.get(), testMediaItems);
assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED); assertThat(timelineChangedReasonRef.get()).isEqualTo(TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
assertThat(onEventsRef.get()).isEqualTo(testEvents); assertThat(onEventsRef.get()).isEqualTo(testEvents);
assertThat(currentWindowIndexRef.get()).isEqualTo(testCurrentWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testCurrentMediaItemIndex);
MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems); MediaTestUtils.assertTimelineContains(timelineFromGetterRef.get(), testMediaItems);
} }
} }

View File

@ -624,76 +624,77 @@ public class MediaControllerWithMediaSessionCompatTest {
} }
@Test @Test
public void seekToDefaultPosition_withWindowIndex_updatesExpectedWindowIndex() throws Exception { public void seekToDefaultPosition_withMediaItemIndex_updatesExpectedMediaItemIndex()
throws Exception {
List<MediaItem> testList = MediaTestUtils.createMediaItems(3); List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
List<QueueItem> testQueue = MediaUtils.convertToQueueItemList(testList); List<QueueItem> testQueue = MediaUtils.convertToQueueItemList(testList);
session.setQueue(testQueue); session.setQueue(testQueue);
session.setPlaybackState(/* state= */ null); session.setPlaybackState(/* state= */ null);
int testWindowIndex = 2; int testMediaItemIndex = 2;
MediaController controller = controllerTestRule.createController(session.getSessionToken()); MediaController controller = controllerTestRule.createController(session.getSessionToken());
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
AtomicInteger currentWindowIndexRef = new AtomicInteger(); AtomicInteger currentMediaItemIndexRef = new AtomicInteger();
Player.Listener listener = Player.Listener listener =
new Player.Listener() { new Player.Listener() {
@Override @Override
public void onPositionDiscontinuity( public void onPositionDiscontinuity(
PositionInfo oldPosition, PositionInfo newPosition, @DiscontinuityReason int reason) { PositionInfo oldPosition, PositionInfo newPosition, @DiscontinuityReason int reason) {
currentWindowIndexRef.set(controller.getCurrentWindowIndex()); currentMediaItemIndexRef.set(controller.getCurrentMediaItemIndex());
latch.countDown(); latch.countDown();
} }
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
threadTestRule threadTestRule
.getHandler() .getHandler()
.postAndSync(() -> controller.seekToDefaultPosition(testWindowIndex)); .postAndSync(() -> controller.seekToDefaultPosition(testMediaItemIndex));
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setActiveQueueItemId(testQueue.get(testWindowIndex).getQueueId()) .setActiveQueueItemId(testQueue.get(testMediaItemIndex).getQueueId())
.build()); .build());
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue(); assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(currentWindowIndexRef.get()).isEqualTo(testWindowIndex); assertThat(currentMediaItemIndexRef.get()).isEqualTo(testMediaItemIndex);
} }
@Test @Test
public void seekTo_withWindowIndex_updatesExpectedWindowIndex() throws Exception { public void seekTo_withMediaItemIndex_updatesExpectedMediaItemIndex() throws Exception {
List<MediaItem> testList = MediaTestUtils.createMediaItems(3); List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
List<QueueItem> testQueue = MediaUtils.convertToQueueItemList(testList); List<QueueItem> testQueue = MediaUtils.convertToQueueItemList(testList);
session.setQueue(testQueue); session.setQueue(testQueue);
session.setPlaybackState(/* state= */ null); session.setPlaybackState(/* state= */ null);
long testPositionMs = 23L; long testPositionMs = 23L;
int testWindowIndex = 2; int testMediaItemIndex = 2;
MediaController controller = controllerTestRule.createController(session.getSessionToken()); MediaController controller = controllerTestRule.createController(session.getSessionToken());
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
AtomicInteger windowIndexFromParamRef = new AtomicInteger(); AtomicInteger mediaItemIndexFromParamRef = new AtomicInteger();
AtomicInteger windowIndexFromGetterRef = new AtomicInteger(); AtomicInteger mediaItemIndexFromGetterRef = new AtomicInteger();
Player.Listener listener = Player.Listener listener =
new Player.Listener() { new Player.Listener() {
@Override @Override
public void onPositionDiscontinuity( public void onPositionDiscontinuity(
PositionInfo oldPosition, PositionInfo newPosition, @DiscontinuityReason int reason) { PositionInfo oldPosition, PositionInfo newPosition, @DiscontinuityReason int reason) {
windowIndexFromParamRef.set(newPosition.mediaItemIndex); mediaItemIndexFromParamRef.set(newPosition.mediaItemIndex);
windowIndexFromGetterRef.set(controller.getCurrentWindowIndex()); mediaItemIndexFromGetterRef.set(controller.getCurrentMediaItemIndex());
latch.countDown(); latch.countDown();
} }
}; };
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener)); threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
threadTestRule threadTestRule
.getHandler() .getHandler()
.postAndSync(() -> controller.seekTo(testWindowIndex, testPositionMs)); .postAndSync(() -> controller.seekTo(testMediaItemIndex, testPositionMs));
session.setPlaybackState( session.setPlaybackState(
new PlaybackStateCompat.Builder() new PlaybackStateCompat.Builder()
.setActiveQueueItemId(testQueue.get(testWindowIndex).getQueueId()) .setActiveQueueItemId(testQueue.get(testMediaItemIndex).getQueueId())
.build()); .build());
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue(); assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(windowIndexFromParamRef.get()).isEqualTo(testWindowIndex); assertThat(mediaItemIndexFromParamRef.get()).isEqualTo(testMediaItemIndex);
assertThat(windowIndexFromGetterRef.get()).isEqualTo(testWindowIndex); assertThat(mediaItemIndexFromGetterRef.get()).isEqualTo(testMediaItemIndex);
} }
@Test @Test
@ -790,7 +791,7 @@ public class MediaControllerWithMediaSessionCompatTest {
} }
@Test @Test
public void getCurrentWindowIndex_withInvalidQueueIdWithMetadata_returnsEndOfList() public void getCurrentMediaItemIndex_withInvalidQueueIdWithMetadata_returnsEndOfList()
throws Exception { throws Exception {
List<MediaItem> testList = MediaTestUtils.createMediaItems(3); List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
List<QueueItem> testQueue = MediaUtils.convertToQueueItemList(testList); List<QueueItem> testQueue = MediaUtils.convertToQueueItemList(testList);
@ -801,8 +802,9 @@ public class MediaControllerWithMediaSessionCompatTest {
session.setMetadata(testMetadataCompat); session.setMetadata(testMetadataCompat);
MediaController controller = controllerTestRule.createController(session.getSessionToken()); MediaController controller = controllerTestRule.createController(session.getSessionToken());
int windowIndex = threadTestRule.getHandler().postAndSync(controller::getCurrentWindowIndex); int mediaItemIndex =
assertThat(windowIndex).isEqualTo(testList.size()); threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItemIndex);
assertThat(mediaItemIndex).isEqualTo(testList.size());
} }
@Test @Test
@ -942,7 +944,8 @@ public class MediaControllerWithMediaSessionCompatTest {
session.setPlaybackState(builder.build()); session.setPlaybackState(builder.build());
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue(); assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
int currentIndex = threadTestRule.getHandler().postAndSync(controller::getCurrentWindowIndex); int currentIndex =
threadTestRule.getHandler().postAndSync(controller::getCurrentMediaItemIndex);
assertThat(currentIndex).isEqualTo(newItemIndex); assertThat(currentIndex).isEqualTo(newItemIndex);
MediaTestUtils.assertMediaIdEquals(testList.get(newItemIndex), itemRef.get()); MediaTestUtils.assertMediaIdEquals(testList.get(newItemIndex), itemRef.get());
assertThat(mediaItemTransitionReasonRef.get()).isEqualTo(MEDIA_ITEM_TRANSITION_REASON_AUTO); assertThat(mediaItemTransitionReasonRef.get()).isEqualTo(MEDIA_ITEM_TRANSITION_REASON_AUTO);

View File

@ -93,9 +93,9 @@ public class MediaSessionAndControllerTest {
MainLooperTestRule.runOnMainSync(() -> player.notifyPlaybackStateChanged(state)); MainLooperTestRule.runOnMainSync(() -> player.notifyPlaybackStateChanged(state));
controller.seekTo(0); controller.seekTo(0);
MainLooperTestRule.runOnMainSync(() -> player.notifyPlaybackStateChanged(state)); MainLooperTestRule.runOnMainSync(() -> player.notifyPlaybackStateChanged(state));
controller.seekToNextWindow(); controller.seekToNextMediaItem();
MainLooperTestRule.runOnMainSync(() -> player.notifyPlaybackStateChanged(state)); MainLooperTestRule.runOnMainSync(() -> player.notifyPlaybackStateChanged(state));
controller.seekToPreviousWindow(); controller.seekToPreviousMediaItem();
} }
}); });
} }

View File

@ -295,14 +295,14 @@ public class MockPlayerTest {
} }
@Test @Test
public void seekToPreviousWindow() { public void seekToPreviousMediaItem() {
player.seekToPreviousWindow(); player.seekToPreviousMediaItem();
assertThat(player.seekToPreviousMediaItemCalled).isTrue(); assertThat(player.seekToPreviousMediaItemCalled).isTrue();
} }
@Test @Test
public void seekToNextWindow() { public void seekToNextMediaItem() {
player.seekToNextWindow(); player.seekToNextMediaItem();
assertThat(player.seekToNextMediaItemCalled).isTrue(); assertThat(player.seekToNextMediaItemCalled).isTrue();
} }

View File

@ -123,7 +123,7 @@ public abstract class Action {
/** Calls {@link Player#seekTo(long)} or {@link Player#seekTo(int, long)}. */ /** Calls {@link Player#seekTo(long)} or {@link Player#seekTo(int, long)}. */
public static final class Seek extends Action { public static final class Seek extends Action {
@Nullable private final Integer windowIndex; @Nullable private final Integer mediaItemIndex;
private final long positionMs; private final long positionMs;
private final boolean catchIllegalSeekException; private final boolean catchIllegalSeekException;
@ -135,7 +135,7 @@ public abstract class Action {
*/ */
public Seek(String tag, long positionMs) { public Seek(String tag, long positionMs) {
super(tag, "Seek:" + positionMs); super(tag, "Seek:" + positionMs);
this.windowIndex = null; this.mediaItemIndex = null;
this.positionMs = positionMs; this.positionMs = positionMs;
catchIllegalSeekException = false; catchIllegalSeekException = false;
} }
@ -144,14 +144,15 @@ public abstract class Action {
* Action calls {@link Player#seekTo(int, long)}. * Action calls {@link Player#seekTo(int, long)}.
* *
* @param tag A tag to use for logging. * @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 positionMs The seek position.
* @param catchIllegalSeekException Whether {@link IllegalSeekPositionException} should be * @param catchIllegalSeekException Whether {@link IllegalSeekPositionException} should be
* silently caught or not. * 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); super(tag, "Seek:" + positionMs);
this.windowIndex = windowIndex; this.mediaItemIndex = mediaItemIndex;
this.positionMs = positionMs; this.positionMs = positionMs;
this.catchIllegalSeekException = catchIllegalSeekException; this.catchIllegalSeekException = catchIllegalSeekException;
} }
@ -160,10 +161,10 @@ public abstract class Action {
protected void doActionImpl( protected void doActionImpl(
ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) { ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) {
try { try {
if (windowIndex == null) { if (mediaItemIndex == null) {
player.seekTo(positionMs); player.seekTo(positionMs);
} else { } else {
player.seekTo(windowIndex, positionMs); player.seekTo(mediaItemIndex, positionMs);
} }
} catch (IllegalSeekPositionException e) { } catch (IllegalSeekPositionException e) {
if (!catchIllegalSeekException) { if (!catchIllegalSeekException) {
@ -176,20 +177,20 @@ public abstract class Action {
/** Calls {@link ExoPlayer#setMediaSources(List, int, long)}. */ /** Calls {@link ExoPlayer#setMediaSources(List, int, long)}. */
public static final class SetMediaItems extends Action { public static final class SetMediaItems extends Action {
private final int windowIndex; private final int mediaItemIndex;
private final long positionMs; private final long positionMs;
private final MediaSource[] mediaSources; private final MediaSource[] mediaSources;
/** /**
* @param tag A tag to use for logging. * @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 positionMs The position in milliseconds to start playback from.
* @param mediaSources The media sources to populate the playlist with. * @param mediaSources The media sources to populate the playlist with.
*/ */
public SetMediaItems( public SetMediaItems(
String tag, int windowIndex, long positionMs, MediaSource... mediaSources) { String tag, int mediaItemIndex, long positionMs, MediaSource... mediaSources) {
super(tag, "SetMediaItems"); super(tag, "SetMediaItems");
this.windowIndex = windowIndex; this.mediaItemIndex = mediaItemIndex;
this.positionMs = positionMs; this.positionMs = positionMs;
this.mediaSources = mediaSources; this.mediaSources = mediaSources;
} }
@ -197,7 +198,7 @@ public abstract class Action {
@Override @Override
protected void doActionImpl( protected void doActionImpl(
ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) { ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) {
player.setMediaSources(Arrays.asList(mediaSources), windowIndex, positionMs); player.setMediaSources(Arrays.asList(mediaSources), mediaItemIndex, positionMs);
} }
} }
@ -555,7 +556,7 @@ public abstract class Action {
public static final class SendMessages extends Action { public static final class SendMessages extends Action {
private final Target target; private final Target target;
private final int windowIndex; private final int mediaItemIndex;
private final long positionMs; private final long positionMs;
private final boolean deleteAfterDelivery; private final boolean deleteAfterDelivery;
@ -568,7 +569,7 @@ public abstract class Action {
this( this(
tag, tag,
target, target,
/* windowIndex= */ C.INDEX_UNSET, /* mediaItemIndex= */ C.INDEX_UNSET,
positionMs, positionMs,
/* deleteAfterDelivery= */ true); /* deleteAfterDelivery= */ true);
} }
@ -576,16 +577,20 @@ public abstract class Action {
/** /**
* @param tag A tag to use for logging. * @param tag A tag to use for logging.
* @param target A message target. * @param target A message target.
* @param windowIndex The window index at which the message should be sent, or {@link * @param mediaItemIndex The media item index at which the message should be sent, or {@link
* C#INDEX_UNSET} for the current window. * C#INDEX_UNSET} for the current media item.
* @param positionMs The position at which the message should be sent, in milliseconds. * @param positionMs The position at which the message should be sent, in milliseconds.
* @param deleteAfterDelivery Whether the message will be deleted after delivery. * @param deleteAfterDelivery Whether the message will be deleted after delivery.
*/ */
public SendMessages( 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"); super(tag, "SendMessages");
this.target = target; this.target = target;
this.windowIndex = windowIndex; this.mediaItemIndex = mediaItemIndex;
this.positionMs = positionMs; this.positionMs = positionMs;
this.deleteAfterDelivery = deleteAfterDelivery; this.deleteAfterDelivery = deleteAfterDelivery;
} }
@ -597,8 +602,8 @@ public abstract class Action {
((PlayerTarget) target).setPlayer(player); ((PlayerTarget) target).setPlayer(player);
} }
PlayerMessage message = player.createMessage(target); PlayerMessage message = player.createMessage(target);
if (windowIndex != C.INDEX_UNSET) { if (mediaItemIndex != C.INDEX_UNSET) {
message.setPosition(windowIndex, positionMs); message.setPosition(mediaItemIndex, positionMs);
} else { } else {
message.setPosition(positionMs); message.setPosition(positionMs);
} }
@ -663,17 +668,17 @@ public abstract class Action {
*/ */
public static final class PlayUntilPosition extends Action { public static final class PlayUntilPosition extends Action {
private final int windowIndex; private final int mediaItemIndex;
private final long positionMs; private final long positionMs;
/** /**
* @param tag A tag to use for logging. * @param tag A tag to use for logging.
* @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.
* @param positionMs The position in that window 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) { public PlayUntilPosition(String tag, int mediaItemIndex, long positionMs) {
super(tag, "PlayUntilPosition:" + windowIndex + ":" + positionMs); super(tag, "PlayUntilPosition:" + mediaItemIndex + ":" + positionMs);
this.windowIndex = windowIndex; this.mediaItemIndex = mediaItemIndex;
this.positionMs = positionMs; this.positionMs = positionMs;
} }
@ -706,7 +711,7 @@ public abstract class Action {
// Ignore. // Ignore.
} }
}) })
.setPosition(windowIndex, positionMs) .setPosition(mediaItemIndex, positionMs)
.send(); .send();
if (nextAction != null) { if (nextAction != null) {
// Schedule another message on this test thread to continue action schedule. // Schedule another message on this test thread to continue action schedule.
@ -714,7 +719,7 @@ public abstract class Action {
.createMessage( .createMessage(
(messageType, payload) -> (messageType, payload) ->
nextAction.schedule(player, trackSelector, surface, handler)) nextAction.schedule(player, trackSelector, surface, handler))
.setPosition(windowIndex, positionMs) .setPosition(mediaItemIndex, positionMs)
.setLooper(applicationLooper) .setLooper(applicationLooper)
.send(); .send();
} }

View File

@ -163,24 +163,25 @@ public final class ActionSchedule {
/** /**
* Schedules a seek action. * Schedules a seek action.
* *
* @param windowIndex The window to seek to. * @param mediaItemIndex The media item to seek to.
* @param positionMs The seek position. * @param positionMs The seek position.
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
public Builder seek(int windowIndex, long positionMs) { public Builder seek(int mediaItemIndex, long positionMs) {
return apply(new Seek(tag, windowIndex, positionMs, /* catchIllegalSeekException= */ false)); return apply(
new Seek(tag, mediaItemIndex, positionMs, /* catchIllegalSeekException= */ false));
} }
/** /**
* Schedules a seek action to be executed. * 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 positionMs The seek position.
* @param catchIllegalSeekException Whether an illegal seek position should be caught or not. * @param catchIllegalSeekException Whether an illegal seek position should be caught or not.
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
public Builder seek(int windowIndex, long positionMs, boolean catchIllegalSeekException) { public Builder seek(int mediaItemIndex, long positionMs, boolean catchIllegalSeekException) {
return apply(new Seek(tag, windowIndex, positionMs, catchIllegalSeekException)); return apply(new Seek(tag, mediaItemIndex, positionMs, catchIllegalSeekException));
} }
/** /**
@ -249,23 +250,23 @@ public final class ActionSchedule {
* Schedules a play action, waits until the player reaches the specified position, and pauses * Schedules a play action, waits until the player reaches the specified position, and pauses
* the player again. * 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.
* @param positionMs The position in that window 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. * @return The builder, for convenience.
*/ */
public Builder playUntilPosition(int windowIndex, long positionMs) { public Builder playUntilPosition(int mediaItemIndex, long positionMs) {
return apply(new PlayUntilPosition(tag, windowIndex, positionMs)); return apply(new PlayUntilPosition(tag, mediaItemIndex, positionMs));
} }
/** /**
* Schedules a play action, waits until the player reaches the start of the specified window, * Schedules a play action, waits until the player reaches the start of the specified media
* and pauses the player again. * 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. * @return The builder, for convenience.
*/ */
public Builder playUntilStartOfWindow(int windowIndex) { public Builder playUntilStartOfMediaItem(int mediaItemIndex) {
return apply(new PlayUntilPosition(tag, windowIndex, /* positionMs= */ 0)); return apply(new PlayUntilPosition(tag, mediaItemIndex, /* positionMs= */ 0));
} }
/** /**
@ -325,16 +326,16 @@ public final class ActionSchedule {
/** /**
* Schedules a set media items action to be executed. * 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 * @param mediaItemIndex The media item index to start playback from or {@link C#INDEX_UNSET} if
* playback position should not be reset. * the playback position should not be reset.
* @param positionMs The position in milliseconds from where playback should start. If {@link * @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} * C#TIME_UNSET} is passed the default position is used. In any case, if {@code
* is set to {@link C#INDEX_UNSET} the position is not reset at all and this parameter is * mediaItemIndex} is set to {@link C#INDEX_UNSET} the position is not reset at all and this
* ignored. * parameter is ignored.
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
public Builder setMediaSources(int windowIndex, long positionMs, MediaSource... sources) { public Builder setMediaSources(int mediaItemIndex, long positionMs, MediaSource... sources) {
return apply(new Action.SetMediaItems(tag, windowIndex, positionMs, sources)); return apply(new Action.SetMediaItems(tag, mediaItemIndex, positionMs, sources));
} }
/** /**
@ -356,7 +357,10 @@ public final class ActionSchedule {
public Builder setMediaSources(MediaSource... mediaSources) { public Builder setMediaSources(MediaSource... mediaSources) {
return apply( return apply(
new Action.SetMediaItems( 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. * Schedules a add media items action to be executed.
@ -449,8 +453,8 @@ public final class ActionSchedule {
/** /**
* Schedules sending a {@link PlayerMessage}. * Schedules sending a {@link PlayerMessage}.
* *
* @param positionMs The position in the current window at which the message should be sent, in * @param positionMs The position in the current media item at which the message should be sent,
* milliseconds. * in milliseconds.
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
public Builder sendMessage(Target target, long positionMs) { public Builder sendMessage(Target target, long positionMs) {
@ -461,27 +465,28 @@ public final class ActionSchedule {
* Schedules sending a {@link PlayerMessage}. * Schedules sending a {@link PlayerMessage}.
* *
* @param target A message target. * @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 positionMs The position at which the message should be sent, in milliseconds.
* @return The builder, for convenience. * @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( return apply(
new SendMessages(tag, target, windowIndex, positionMs, /* deleteAfterDelivery= */ true)); new SendMessages(
tag, target, mediaItemIndex, positionMs, /* deleteAfterDelivery= */ true));
} }
/** /**
* Schedules to send a {@link PlayerMessage}. * Schedules to send a {@link PlayerMessage}.
* *
* @param target A message target. * @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 positionMs The position at which the message should be sent, in milliseconds.
* @param deleteAfterDelivery Whether the message will be deleted after delivery. * @param deleteAfterDelivery Whether the message will be deleted after delivery.
* @return The builder, for convenience. * @return The builder, for convenience.
*/ */
public Builder sendMessage( public Builder sendMessage(
Target target, int windowIndex, long positionMs, boolean deleteAfterDelivery) { Target target, int mediaItemIndex, long positionMs, boolean deleteAfterDelivery) {
return apply(new SendMessages(tag, target, windowIndex, positionMs, deleteAfterDelivery)); return apply(new SendMessages(tag, target, mediaItemIndex, positionMs, deleteAfterDelivery));
} }
/** /**

View File

@ -87,7 +87,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul
private AnalyticsListener analyticsListener; private AnalyticsListener analyticsListener;
private Integer expectedPlayerEndedCount; private Integer expectedPlayerEndedCount;
private boolean pauseAtEndOfMediaItems; private boolean pauseAtEndOfMediaItems;
private int initialWindowIndex; private int initialMediaItemIndex;
private long initialPositionMs; private long initialPositionMs;
private boolean skipSettingMediaSources; private boolean skipSettingMediaSources;
@ -95,7 +95,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul
testPlayerBuilder = new TestExoPlayerBuilder(context); testPlayerBuilder = new TestExoPlayerBuilder(context);
mediaSources = new ArrayList<>(); mediaSources = new ArrayList<>();
supportedFormats = new Format[] {VIDEO_FORMAT}; supportedFormats = new Format[] {VIDEO_FORMAT};
initialWindowIndex = C.INDEX_UNSET; initialMediaItemIndex = C.INDEX_UNSET;
initialPositionMs = C.TIME_UNSET; initialPositionMs = C.TIME_UNSET;
} }
@ -135,12 +135,12 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul
/** /**
* Seeks before setting the media sources and preparing the player. * 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. * @param positionMs The position in milliseconds to seek to.
* @return This builder. * @return This builder.
*/ */
public Builder initialSeek(int windowIndex, long positionMs) { public Builder initialSeek(int mediaItemIndex, long positionMs) {
this.initialWindowIndex = windowIndex; this.initialMediaItemIndex = mediaItemIndex;
this.initialPositionMs = positionMs; this.initialPositionMs = positionMs;
return this; return this;
} }
@ -345,7 +345,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul
testPlayerBuilder, testPlayerBuilder,
mediaSources, mediaSources,
skipSettingMediaSources, skipSettingMediaSources,
initialWindowIndex, initialMediaItemIndex,
initialPositionMs, initialPositionMs,
surface, surface,
actionSchedule, actionSchedule,
@ -359,7 +359,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul
private final TestExoPlayerBuilder playerBuilder; private final TestExoPlayerBuilder playerBuilder;
private final List<MediaSource> mediaSources; private final List<MediaSource> mediaSources;
private final boolean skipSettingMediaSources; private final boolean skipSettingMediaSources;
private final int initialWindowIndex; private final int initialMediaItemIndex;
private final long initialPositionMs; private final long initialPositionMs;
@Nullable private final Surface surface; @Nullable private final Surface surface;
@Nullable private final ActionSchedule actionSchedule; @Nullable private final ActionSchedule actionSchedule;
@ -388,7 +388,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul
TestExoPlayerBuilder playerBuilder, TestExoPlayerBuilder playerBuilder,
List<MediaSource> mediaSources, List<MediaSource> mediaSources,
boolean skipSettingMediaSources, boolean skipSettingMediaSources,
int initialWindowIndex, int initialMediaItemIndex,
long initialPositionMs, long initialPositionMs,
@Nullable Surface surface, @Nullable Surface surface,
@Nullable ActionSchedule actionSchedule, @Nullable ActionSchedule actionSchedule,
@ -399,7 +399,7 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul
this.playerBuilder = playerBuilder; this.playerBuilder = playerBuilder;
this.mediaSources = mediaSources; this.mediaSources = mediaSources;
this.skipSettingMediaSources = skipSettingMediaSources; this.skipSettingMediaSources = skipSettingMediaSources;
this.initialWindowIndex = initialWindowIndex; this.initialMediaItemIndex = initialMediaItemIndex;
this.initialPositionMs = initialPositionMs; this.initialPositionMs = initialPositionMs;
this.surface = surface; this.surface = surface;
this.actionSchedule = actionSchedule; this.actionSchedule = actionSchedule;
@ -468,8 +468,8 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul
handler, handler,
/* callback= */ ExoPlayerTestRunner.this); /* callback= */ ExoPlayerTestRunner.this);
} }
if (initialWindowIndex != C.INDEX_UNSET) { if (initialMediaItemIndex != C.INDEX_UNSET) {
player.seekTo(initialWindowIndex, initialPositionMs); player.seekTo(initialMediaItemIndex, initialPositionMs);
} }
if (!skipSettingMediaSources) { if (!skipSettingMediaSources) {
player.setMediaSources(mediaSources, /* resetPosition= */ false); player.setMediaSources(mediaSources, /* resetPosition= */ false);

View File

@ -164,7 +164,7 @@ public class StubExoPlayer extends StubPlayer implements ExoPlayer {
@Override @Override
public void setMediaSources( public void setMediaSources(
List<MediaSource> mediaSources, int startWindowIndex, long startPositionMs) { List<MediaSource> mediaSources, int startMediaItemIndex, long startPositionMs) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

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

View File

@ -952,7 +952,7 @@ public class PlayerControlView extends FrameLayout {
int adGroupCount = 0; int adGroupCount = 0;
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
if (!timeline.isEmpty()) { if (!timeline.isEmpty()) {
int currentWindowIndex = player.getCurrentWindowIndex(); int currentWindowIndex = player.getCurrentMediaItemIndex();
int firstWindowIndex = multiWindowTimeBar ? 0 : currentWindowIndex; int firstWindowIndex = multiWindowTimeBar ? 0 : currentWindowIndex;
int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex; int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex;
for (int i = firstWindowIndex; i <= lastWindowIndex; i++) { for (int i = firstWindowIndex; i <= lastWindowIndex; i++) {
@ -1112,7 +1112,7 @@ public class PlayerControlView extends FrameLayout {
windowIndex++; windowIndex++;
} }
} else { } else {
windowIndex = player.getCurrentWindowIndex(); windowIndex = player.getCurrentMediaItemIndex();
} }
seekTo(player, windowIndex, positionMs); seekTo(player, windowIndex, positionMs);
updateProgress(); updateProgress();
@ -1230,7 +1230,7 @@ public class PlayerControlView extends FrameLayout {
if (state == Player.STATE_IDLE) { if (state == Player.STATE_IDLE) {
player.prepare(); player.prepare();
} else if (state == Player.STATE_ENDED) { } else if (state == Player.STATE_ENDED) {
seekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); seekTo(player, player.getCurrentMediaItemIndex(), C.TIME_UNSET);
} }
player.play(); player.play();
} }

View File

@ -607,9 +607,9 @@ public class PlayerNotificationManager {
public static final String ACTION_PLAY = "androidx.media3.ui.notification.play"; public static final String ACTION_PLAY = "androidx.media3.ui.notification.play";
/** The action which pauses playback. */ /** The action which pauses playback. */
public static final String ACTION_PAUSE = "androidx.media3.ui.notification.pause"; public static final String ACTION_PAUSE = "androidx.media3.ui.notification.pause";
/** The action which skips to the previous window. */ /** The action which skips to the previous media item. */
public static final String ACTION_PREVIOUS = "androidx.media3.ui.notification.prev"; public static final String ACTION_PREVIOUS = "androidx.media3.ui.notification.prev";
/** The action which skips to the next window. */ /** The action which skips to the next media item. */
public static final String ACTION_NEXT = "androidx.media3.ui.notification.next"; public static final String ACTION_NEXT = "androidx.media3.ui.notification.next";
/** The action which fast forwards. */ /** The action which fast forwards. */
public static final String ACTION_FAST_FORWARD = "androidx.media3.ui.notification.ffwd"; public static final String ACTION_FAST_FORWARD = "androidx.media3.ui.notification.ffwd";
@ -1097,7 +1097,7 @@ public class PlayerNotificationManager {
* *
* <ul> * <ul>
* <li>The media is {@link Player#isPlaying() actively playing}. * <li>The media is {@link Player#isPlaying() actively playing}.
* <li>The media is not {@link Player#isCurrentWindowDynamic() dynamically changing its * <li>The media is not {@link Player#isCurrentMediaItemDynamic() dynamically changing its
* duration} (like for example a live stream). * duration} (like for example a live stream).
* <li>The media is not {@link Player#isPlayingAd() interrupted by an ad}. * <li>The media is not {@link Player#isPlayingAd() interrupted by an ad}.
* <li>The media is played at {@link Player#getPlaybackParameters() regular speed}. * <li>The media is played at {@link Player#getPlaybackParameters() regular speed}.
@ -1255,7 +1255,7 @@ public class PlayerNotificationManager {
&& useChronometer && useChronometer
&& player.isPlaying() && player.isPlaying()
&& !player.isPlayingAd() && !player.isPlayingAd()
&& !player.isCurrentWindowDynamic() && !player.isCurrentMediaItemDynamic()
&& player.getPlaybackParameters().speed == 1f) { && player.getPlaybackParameters().speed == 1f) {
builder builder
.setWhen(System.currentTimeMillis() - player.getContentPosition()) .setWhen(System.currentTimeMillis() - player.getContentPosition())
@ -1533,7 +1533,7 @@ public class PlayerNotificationManager {
if (player.getPlaybackState() == Player.STATE_IDLE) { if (player.getPlaybackState() == Player.STATE_IDLE) {
player.prepare(); player.prepare();
} else if (player.getPlaybackState() == Player.STATE_ENDED) { } else if (player.getPlaybackState() == Player.STATE_ENDED) {
player.seekToDefaultPosition(player.getCurrentWindowIndex()); player.seekToDefaultPosition(player.getCurrentMediaItemIndex());
} }
player.play(); player.play();
} else if (ACTION_PAUSE.equals(action)) { } else if (ACTION_PAUSE.equals(action)) {

View File

@ -1504,8 +1504,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
if (lastPeriodIndexWithTracks != C.INDEX_UNSET) { if (lastPeriodIndexWithTracks != C.INDEX_UNSET) {
int lastWindowIndexWithTracks = int lastWindowIndexWithTracks =
timeline.getPeriod(lastPeriodIndexWithTracks, period).windowIndex; timeline.getPeriod(lastPeriodIndexWithTracks, period).windowIndex;
if (player.getCurrentWindowIndex() == lastWindowIndexWithTracks) { if (player.getCurrentMediaItemIndex() == lastWindowIndexWithTracks) {
// We're in the same window. Suppress the update. // We're in the same media item. Suppress the update.
return; return;
} }
} }

View File

@ -1271,7 +1271,7 @@ public class StyledPlayerControlView extends FrameLayout {
int adGroupCount = 0; int adGroupCount = 0;
Timeline timeline = player.getCurrentTimeline(); Timeline timeline = player.getCurrentTimeline();
if (!timeline.isEmpty()) { if (!timeline.isEmpty()) {
int currentWindowIndex = player.getCurrentWindowIndex(); int currentWindowIndex = player.getCurrentMediaItemIndex();
int firstWindowIndex = multiWindowTimeBar ? 0 : currentWindowIndex; int firstWindowIndex = multiWindowTimeBar ? 0 : currentWindowIndex;
int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex; int lastWindowIndex = multiWindowTimeBar ? timeline.getWindowCount() - 1 : currentWindowIndex;
for (int i = firstWindowIndex; i <= lastWindowIndex; i++) { for (int i = firstWindowIndex; i <= lastWindowIndex; i++) {
@ -1455,7 +1455,7 @@ public class StyledPlayerControlView extends FrameLayout {
windowIndex++; windowIndex++;
} }
} else { } else {
windowIndex = player.getCurrentWindowIndex(); windowIndex = player.getCurrentMediaItemIndex();
} }
seekTo(player, windowIndex, positionMs); seekTo(player, windowIndex, positionMs);
updateProgress(); updateProgress();
@ -1618,13 +1618,12 @@ public class StyledPlayerControlView extends FrameLayout {
} }
} }
@SuppressWarnings("deprecation")
private void dispatchPlay(Player player) { private void dispatchPlay(Player player) {
@State int state = player.getPlaybackState(); @State int state = player.getPlaybackState();
if (state == Player.STATE_IDLE) { if (state == Player.STATE_IDLE) {
player.prepare(); player.prepare();
} else if (state == Player.STATE_ENDED) { } else if (state == Player.STATE_ENDED) {
seekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); seekTo(player, player.getCurrentMediaItemIndex(), C.TIME_UNSET);
} }
player.play(); player.play();
} }

View File

@ -1543,8 +1543,8 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
if (lastPeriodIndexWithTracks != C.INDEX_UNSET) { if (lastPeriodIndexWithTracks != C.INDEX_UNSET) {
int lastWindowIndexWithTracks = int lastWindowIndexWithTracks =
timeline.getPeriod(lastPeriodIndexWithTracks, period).windowIndex; timeline.getPeriod(lastPeriodIndexWithTracks, period).windowIndex;
if (player.getCurrentWindowIndex() == lastWindowIndexWithTracks) { if (player.getCurrentMediaItemIndex() == lastWindowIndexWithTracks) {
// We're in the same window. Suppress the update. // We're in the same media item. Suppress the update.
return; return;
} }
} }

View File

@ -143,7 +143,7 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab
if (player.getPlaybackState() == Player.STATE_IDLE) { if (player.getPlaybackState() == Player.STATE_IDLE) {
player.prepare(); player.prepare();
} else if (player.getPlaybackState() == Player.STATE_ENDED) { } else if (player.getPlaybackState() == Player.STATE_ENDED) {
player.seekToDefaultPosition(player.getCurrentWindowIndex()); player.seekToDefaultPosition(player.getCurrentMediaItemIndex());
} }
if (player.isCommandAvailable(Player.COMMAND_PLAY_PAUSE)) { if (player.isCommandAvailable(Player.COMMAND_PLAY_PAUSE)) {
player.play(); player.play();