Commit c033263d by tianyifeng Committed by Tianyi Feng

Ensure that ShuffleOrder has the same length as the current playlist

Add a fail-fast check in `ExoPlayerImpl` to ensure the equality of the lengths of `ShuffleOrder` and the current playlist. Also improve the documentation of `setShuffleOrder(ShuffleOrder)` with explicit instruction on this.

Issue: androidx/media#480

#minor-release

PiperOrigin-RevId: 544009359
(cherry picked from commit 9cabbc9badbc9301f5e13398b8444377c4e72543)
parent f6042d63
...@@ -1409,6 +1409,9 @@ public interface ExoPlayer extends Player { ...@@ -1409,6 +1409,9 @@ public interface ExoPlayer extends Player {
/** /**
* Sets the shuffle order. * Sets the shuffle order.
* *
* <p>The {@link ShuffleOrder} passed must have the same length as the current playlist ({@link
* Player#getMediaItemCount()}).
*
* @param shuffleOrder The shuffle order. * @param shuffleOrder The shuffle order.
*/ */
void setShuffleOrder(ShuffleOrder shuffleOrder); void setShuffleOrder(ShuffleOrder shuffleOrder);
......
...@@ -762,6 +762,7 @@ import java.util.concurrent.TimeoutException; ...@@ -762,6 +762,7 @@ import java.util.concurrent.TimeoutException;
@Override @Override
public void setShuffleOrder(ShuffleOrder shuffleOrder) { public void setShuffleOrder(ShuffleOrder shuffleOrder) {
verifyApplicationThread(); verifyApplicationThread();
checkArgument(shuffleOrder.getLength() == mediaSourceHolderSnapshots.size());
this.shuffleOrder = shuffleOrder; this.shuffleOrder = shuffleOrder;
Timeline timeline = createMaskingTimeline(); Timeline timeline = createMaskingTimeline();
PlaybackInfo newPlaybackInfo = PlaybackInfo newPlaybackInfo =
......
...@@ -6946,6 +6946,15 @@ public final class ExoPlayerTest { ...@@ -6946,6 +6946,15 @@ public final class ExoPlayerTest {
} }
@Test @Test
public void setShuffleOrder_shuffleOrderLengthNotEqualToCurrentPlaylistLength_shouldThrow() {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
assertThrows(
IllegalArgumentException.class, () -> player.setShuffleOrder(new FakeShuffleOrder(3)));
}
@Test
public void setMediaSources_empty_whenEmpty_correctMaskingMediaItemIndex() throws Exception { public void setMediaSources_empty_whenEmpty_correctMaskingMediaItemIndex() throws Exception {
final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET}; final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET};
ActionSchedule actionSchedule = ActionSchedule actionSchedule =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment