diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 54e53770c56..28eb683b0d0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -13,6 +13,8 @@ * Throw `IllegalStateException` when `PreloadMediaSource` is played by an `ExoPlayer` with a playback thread that is different than the preload thread ([#2495](https://github.com/androidx/media/issues/2495)). + * Add `cloneAndMove` to `ShuffleMode` with a default implementation + ([#2226](https://github.com/androidx/media/pull/2226)). * Transformer: * Add `CodecDbLite` that enables chipset specific optimizations of video encoding settings. 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 fe2a62b2f0f..11e9a0c5887 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java @@ -704,6 +704,7 @@ public void moveMediaItems(int fromIndex, int toIndex, int newFromIndex) { Timeline oldTimeline = getCurrentTimeline(); pendingOperationAcks++; Util.moveItems(mediaSourceHolderSnapshots, fromIndex, toIndex, newFromIndex); + shuffleOrder = shuffleOrder.cloneAndMove(fromIndex, toIndex, newFromIndex); Timeline newTimeline = createMaskingTimeline(); PlaybackInfo newPlaybackInfo = maskTimelineAndPosition( diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ShuffleOrder.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ShuffleOrder.java index e6e2e1b2dcd..dbdf2f272f8 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ShuffleOrder.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ShuffleOrder.java @@ -266,6 +266,24 @@ public ShuffleOrder cloneAndClear() { */ ShuffleOrder cloneAndInsert(int insertionIndex, int insertionCount); + /** + * Returns a copy of the shuffle order to be used after a move. + * + *

The default implementation is a no-op. Custom implementation can choose to re-shuffle when + * items are moved. + * + * @param indexFrom The starting index in the unshuffled order of the range to move, from before + * the move occurs. + * @param indexToExclusive The smallest index (must be greater or equal to {@code indexFrom}) that + * is not included in the range of elements moved, from before the move occurs. + * @param newIndexFrom The starting index in the unshuffled order of the range to move, from after + * the move occurs. + * @return A copy of this {@link ShuffleOrder} with the elements moved. + */ + default ShuffleOrder cloneAndMove(int indexFrom, int indexToExclusive, int newIndexFrom) { + return this; + } + /** * Returns a copy of the shuffle order with a range of elements removed. *