Skip to content

Commit 7fe8823

Browse files
nift4marcbaechinger
authored andcommitted
notify ShuffleOrder when media item(s) are moved
Issue: #1932 Issue: #1381
1 parent 8bc34a1 commit 7fe8823

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ public void moveMediaItems(int fromIndex, int toIndex, int newFromIndex) {
703703
}
704704
Timeline oldTimeline = getCurrentTimeline();
705705
pendingOperationAcks++;
706-
Util.moveItems(mediaSourceHolderSnapshots, fromIndex, toIndex, newFromIndex);
706+
moveMediaSourceHolders(fromIndex, toIndex, newFromIndex);
707707
Timeline newTimeline = createMaskingTimeline();
708708
PlaybackInfo newPlaybackInfo =
709709
maskTimelineAndPosition(
@@ -725,6 +725,11 @@ public void moveMediaItems(int fromIndex, int toIndex, int newFromIndex) {
725725
/* repeatCurrentMediaItem= */ false);
726726
}
727727

728+
private void moveMediaSourceHolders(int fromIndex, int toIndex, int newFromIndex) {
729+
Util.moveItems(mediaSourceHolderSnapshots, fromIndex, toIndex, newFromIndex);
730+
shuffleOrder = shuffleOrder.cloneAndMove(fromIndex, toIndex, newFromIndex);
731+
}
732+
728733
@Override
729734
public void replaceMediaItems(int fromIndex, int toIndex, List<MediaItem> mediaItems) {
730735
verifyApplicationThread();

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

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

269+
/**
270+
* Returns a copy of the shuffle order with a range of elements moved.
271+
*
272+
* @param indexFrom The starting index in the unshuffled order of the range to move, from before
273+
* the move occurs.
274+
* @param indexToExclusive The smallest index (must be greater or equal to {@code indexFrom}) that
275+
* is not included in the range of elements moved, from before the move occurs.
276+
* @param newIndexFrom The starting index in the unshuffled order of the range to move, from after
277+
* the move occurs.
278+
* @return A copy of this {@link ShuffleOrder} with the elements moved.
279+
*/
280+
default ShuffleOrder cloneAndMove(int indexFrom, int indexToExclusive, int newIndexFrom) {
281+
return cloneAndRemove(indexFrom, indexToExclusive)
282+
.cloneAndInsert(newIndexFrom, indexToExclusive - indexFrom);
283+
}
284+
269285
/**
270286
* Returns a copy of the shuffle order with a range of elements removed.
271287
*

0 commit comments

Comments
 (0)