mirror of
https://github.com/samsonjs/media.git
synced 2026-04-03 10:55:48 +00:00
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 d895a46b28)
This commit is contained in:
parent
f768fedaee
commit
52706b2eb4
3 changed files with 13 additions and 0 deletions
|
|
@ -1469,6 +1469,9 @@ public interface ExoPlayer extends Player {
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
@UnstableApi
|
||||
|
|
|
|||
|
|
@ -765,6 +765,7 @@ import java.util.concurrent.TimeoutException;
|
|||
@Override
|
||||
public void setShuffleOrder(ShuffleOrder shuffleOrder) {
|
||||
verifyApplicationThread();
|
||||
checkArgument(shuffleOrder.getLength() == mediaSourceHolderSnapshots.size());
|
||||
this.shuffleOrder = shuffleOrder;
|
||||
Timeline timeline = createMaskingTimeline();
|
||||
PlaybackInfo newPlaybackInfo =
|
||||
|
|
|
|||
|
|
@ -6955,6 +6955,15 @@ public final class ExoPlayerTest {
|
|||
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
|
||||
public void setMediaSources_empty_whenEmpty_correctMaskingMediaItemIndex() throws Exception {
|
||||
final int[] currentMediaItemIndices = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET};
|
||||
|
|
|
|||
Loading…
Reference in a new issue