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
This commit is contained in:
parent
fd284d7de2
commit
d895a46b28
@ -1494,6 +1494,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.
|
||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
|
@ -776,6 +776,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 =
|
||||||
|
@ -6961,6 +6961,15 @@ public final class ExoPlayerTest {
|
|||||||
assertThat(capturedTimelineShuffleIndexes).isEqualTo(newShuffleOrderIndexes);
|
assertThat(capturedTimelineShuffleIndexes).isEqualTo(newShuffleOrderIndexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@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};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user