Skip to content

Commit fe98cd7

Browse files
Merge pull request #2226 from nift4:shuffle
PiperOrigin-RevId: 770065234
2 parents e7ab781 + ad92956 commit fe98cd7

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

RELEASENOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* Throw `IllegalStateException` when `PreloadMediaSource` is played by an
1414
`ExoPlayer` with a playback thread that is different than the preload
1515
thread ([#2495](https://github.com/androidx/media/issues/2495)).
16+
* Add `cloneAndMove` to `ShuffleMode` with a default implementation
17+
([#2226](https://github.com/androidx/media/pull/2226)).
1618
* Transformer:
1719
* Add `CodecDbLite` that enables chipset specific optimizations of video
1820
encoding settings.

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ public void moveMediaItems(int fromIndex, int toIndex, int newFromIndex) {
704704
Timeline oldTimeline = getCurrentTimeline();
705705
pendingOperationAcks++;
706706
Util.moveItems(mediaSourceHolderSnapshots, fromIndex, toIndex, newFromIndex);
707+
shuffleOrder = shuffleOrder.cloneAndMove(fromIndex, toIndex, newFromIndex);
707708
Timeline newTimeline = createMaskingTimeline();
708709
PlaybackInfo newPlaybackInfo =
709710
maskTimelineAndPosition(

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ShuffleOrder.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,24 @@ public ShuffleOrder cloneAndClear() {
266266
*/
267267
ShuffleOrder cloneAndInsert(int insertionIndex, int insertionCount);
268268

269+
/**
270+
* Returns a copy of the shuffle order to be used after a move.
271+
*
272+
* <p>The default implementation is a no-op. Custom implementation can choose to re-shuffle when
273+
* items are moved.
274+
*
275+
* @param indexFrom The starting index in the unshuffled order of the range to move, from before
276+
* the move occurs.
277+
* @param indexToExclusive The smallest index (must be greater or equal to {@code indexFrom}) that
278+
* is not included in the range of elements moved, from before the move occurs.
279+
* @param newIndexFrom The starting index in the unshuffled order of the range to move, from after
280+
* the move occurs.
281+
* @return A copy of this {@link ShuffleOrder} with the elements moved.
282+
*/
283+
default ShuffleOrder cloneAndMove(int indexFrom, int indexToExclusive, int newIndexFrom) {
284+
return this;
285+
}
286+
269287
/**
270288
* Returns a copy of the shuffle order with a range of elements removed.
271289
*

0 commit comments

Comments
 (0)