diff --git a/RELEASENOTES.md b/RELEASENOTES.md index dc4cf13519..757f51d57d 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -23,6 +23,9 @@ ([#8944](https://github.com/google/ExoPlayer/issues/8944)). * Fix session tracking problem with fast seeks in `PlaybackStatsListener` ([#180](https://github.com/androidx/media/issues/180)). + * Send missing `onMediaItemTransition` callback when calling `seekToNext` + or `seekToPrevious` in a single-item playlist + ([#10667](https://github.com/google/ExoPlayer/issues/10667)). * Downloads: * Fix potential infinite loop in `ProgressiveDownloader` caused by simultaneous download and playback with the same `PriorityTaskManager` diff --git a/libraries/common/src/main/java/androidx/media3/common/BasePlayer.java b/libraries/common/src/main/java/androidx/media3/common/BasePlayer.java index 9069f061bb..74b144baa3 100644 --- a/libraries/common/src/main/java/androidx/media3/common/BasePlayer.java +++ b/libraries/common/src/main/java/androidx/media3/common/BasePlayer.java @@ -22,6 +22,7 @@ import androidx.annotation.Nullable; import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.Util; import com.google.common.collect.ImmutableList; +import com.google.errorprone.annotations.ForOverride; import java.util.List; /** Abstract base {@link Player} which implements common implementation independent methods. */ @@ -187,7 +188,12 @@ public abstract class BasePlayer implements Player { @Override public final void seekToPreviousMediaItem() { int previousMediaItemIndex = getPreviousMediaItemIndex(); - if (previousMediaItemIndex != C.INDEX_UNSET) { + if (previousMediaItemIndex == C.INDEX_UNSET) { + return; + } + if (previousMediaItemIndex == getCurrentMediaItemIndex()) { + repeatCurrentMediaItem(); + } else { seekToDefaultPosition(previousMediaItemIndex); } } @@ -254,7 +260,12 @@ public abstract class BasePlayer implements Player { @Override public final void seekToNextMediaItem() { int nextMediaItemIndex = getNextMediaItemIndex(); - if (nextMediaItemIndex != C.INDEX_UNSET) { + if (nextMediaItemIndex == C.INDEX_UNSET) { + return; + } + if (nextMediaItemIndex == getCurrentMediaItemIndex()) { + repeatCurrentMediaItem(); + } else { seekToDefaultPosition(nextMediaItemIndex); } } @@ -426,6 +437,17 @@ public abstract class BasePlayer implements Player { : timeline.getWindow(getCurrentMediaItemIndex(), window).getDurationMs(); } + /** + * Repeat the current media item. + * + *
The default implementation seeks to the default position in the current item, which can be
+ * overridden for additional handling.
+ */
+ @ForOverride
+ protected void repeatCurrentMediaItem() {
+ seekToDefaultPosition();
+ }
+
private @RepeatMode int getRepeatModeForNavigation() {
@RepeatMode int repeatMode = getRepeatMode();
return repeatMode == REPEAT_MODE_ONE ? REPEAT_MODE_OFF : repeatMode;
diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java
index bf78533492..64f1236bda 100644
--- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java
+++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java
@@ -542,7 +542,8 @@ import java.util.concurrent.TimeoutException;
/* positionDiscontinuity= */ false,
/* ignored */ DISCONTINUITY_REASON_INTERNAL,
/* ignored */ C.TIME_UNSET,
- /* ignored */ C.INDEX_UNSET);
+ /* ignored */ C.INDEX_UNSET,
+ /* repeatCurrentMediaItem= */ false);
}
@Override
@@ -663,7 +664,8 @@ import java.util.concurrent.TimeoutException;
/* positionDiscontinuity= */ false,
/* ignored */ DISCONTINUITY_REASON_INTERNAL,
/* ignored */ C.TIME_UNSET,
- /* ignored */ C.INDEX_UNSET);
+ /* ignored */ C.INDEX_UNSET,
+ /* repeatCurrentMediaItem= */ false);
}
@Override
@@ -681,7 +683,8 @@ import java.util.concurrent.TimeoutException;
positionDiscontinuity,
DISCONTINUITY_REASON_REMOVE,
/* discontinuityWindowStartPositionUs= */ getCurrentPositionUsInternal(newPlaybackInfo),
- /* ignored */ C.INDEX_UNSET);
+ /* ignored */ C.INDEX_UNSET,
+ /* repeatCurrentMediaItem= */ false);
}
@Override
@@ -711,7 +714,8 @@ import java.util.concurrent.TimeoutException;
/* positionDiscontinuity= */ false,
/* ignored */ DISCONTINUITY_REASON_INTERNAL,
/* ignored */ C.TIME_UNSET,
- /* ignored */ C.INDEX_UNSET);
+ /* ignored */ C.INDEX_UNSET,
+ /* repeatCurrentMediaItem= */ false);
}
@Override
@@ -735,7 +739,8 @@ import java.util.concurrent.TimeoutException;
/* positionDiscontinuity= */ false,
/* ignored */ DISCONTINUITY_REASON_INTERNAL,
/* ignored */ C.TIME_UNSET,
- /* ignored */ C.INDEX_UNSET);
+ /* ignored */ C.INDEX_UNSET,
+ /* repeatCurrentMediaItem= */ false);
}
@Override
@@ -814,47 +819,17 @@ import java.util.concurrent.TimeoutException;
return playbackInfo.isLoading;
}
+ @Override
+ protected void repeatCurrentMediaItem() {
+ verifyApplicationThread();
+ seekToInternal(
+ getCurrentMediaItemIndex(), /* positionMs= */ C.TIME_UNSET, /* repeatMediaItem= */ true);
+ }
+
@Override
public void seekTo(int mediaItemIndex, long positionMs) {
verifyApplicationThread();
- analyticsCollector.notifySeekStarted();
- Timeline timeline = playbackInfo.timeline;
- if (mediaItemIndex < 0
- || (!timeline.isEmpty() && mediaItemIndex >= timeline.getWindowCount())) {
- throw new IllegalSeekPositionException(timeline, mediaItemIndex, positionMs);
- }
- pendingOperationAcks++;
- if (isPlayingAd()) {
- // TODO: Investigate adding support for seeking during ads. This is complicated to do in
- // general because the midroll ad preceding the seek destination must be played before the
- // content position can be played, if a different ad is playing at the moment.
- Log.w(TAG, "seekTo ignored because an ad is playing");
- ExoPlayerImplInternal.PlaybackInfoUpdate playbackInfoUpdate =
- new ExoPlayerImplInternal.PlaybackInfoUpdate(this.playbackInfo);
- playbackInfoUpdate.incrementPendingOperationAcks(1);
- playbackInfoUpdateListener.onPlaybackInfoUpdate(playbackInfoUpdate);
- return;
- }
- @Player.State
- int newPlaybackState =
- getPlaybackState() == Player.STATE_IDLE ? Player.STATE_IDLE : STATE_BUFFERING;
- int oldMaskingMediaItemIndex = getCurrentMediaItemIndex();
- PlaybackInfo newPlaybackInfo = playbackInfo.copyWithPlaybackState(newPlaybackState);
- newPlaybackInfo =
- maskTimelineAndPosition(
- newPlaybackInfo,
- timeline,
- maskWindowPositionMsOrGetPeriodPositionUs(timeline, mediaItemIndex, positionMs));
- internalPlayer.seekTo(timeline, mediaItemIndex, Util.msToUs(positionMs));
- updatePlaybackInfo(
- newPlaybackInfo,
- /* ignored */ TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
- /* ignored */ PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST,
- /* seekProcessed= */ true,
- /* positionDiscontinuity= */ true,
- /* positionDiscontinuityReason= */ DISCONTINUITY_REASON_SEEK,
- /* discontinuityWindowStartPositionUs= */ getCurrentPositionUsInternal(newPlaybackInfo),
- oldMaskingMediaItemIndex);
+ seekToInternal(mediaItemIndex, positionMs, /* repeatMediaItem= */ false);
}
@Override
@@ -895,7 +870,8 @@ import java.util.concurrent.TimeoutException;
/* positionDiscontinuity= */ false,
/* ignored */ DISCONTINUITY_REASON_INTERNAL,
/* ignored */ C.TIME_UNSET,
- /* ignored */ C.INDEX_UNSET);
+ /* ignored */ C.INDEX_UNSET,
+ /* repeatCurrentMediaItem= */ false);
}
@Override
@@ -1744,7 +1720,8 @@ import java.util.concurrent.TimeoutException;
positionDiscontinuity,
DISCONTINUITY_REASON_REMOVE,
/* discontinuityWindowStartPositionUs= */ getCurrentPositionUsInternal(playbackInfo),
- /* ignored */ C.INDEX_UNSET);
+ /* ignored */ C.INDEX_UNSET,
+ /* repeatCurrentMediaItem= */ false);
}
private int getCurrentWindowIndexInternal() {
@@ -1826,7 +1803,8 @@ import java.util.concurrent.TimeoutException;
positionDiscontinuity,
pendingDiscontinuityReason,
discontinuityWindowStartPositionUs,
- /* ignored */ C.INDEX_UNSET);
+ /* ignored */ C.INDEX_UNSET,
+ /* repeatCurrentMediaItem= */ false);
}
}
@@ -1840,7 +1818,8 @@ import java.util.concurrent.TimeoutException;
boolean positionDiscontinuity,
@DiscontinuityReason int positionDiscontinuityReason,
long discontinuityWindowStartPositionUs,
- int oldMaskingMediaItemIndex) {
+ int oldMaskingMediaItemIndex,
+ boolean repeatCurrentMediaItem) {
// 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.
@@ -1848,13 +1827,15 @@ import java.util.concurrent.TimeoutException;
PlaybackInfo newPlaybackInfo = playbackInfo;
this.playbackInfo = playbackInfo;
+ boolean timelineChanged = !previousPlaybackInfo.timeline.equals(newPlaybackInfo.timeline);
Pair