mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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.
|
* 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
|
||||||
|
|
|
||||||
|
|
@ -765,6 +765,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 =
|
||||||
|
|
|
||||||
|
|
@ -6955,6 +6955,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…
Reference in a new issue