Commit 4883a9ba by tonihei Committed by Oliver Woodman

Add shuffle support to infinitely looping timeline.

In addition, let unit test assert window indices for both shuffle modes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166191069
parent bd811818
...@@ -42,44 +42,55 @@ public class LoopingMediaSourceTest extends TestCase { ...@@ -42,44 +42,55 @@ public class LoopingMediaSourceTest extends TestCase {
Timeline timeline = getLoopingTimeline(multiWindowTimeline, 1); Timeline timeline = getLoopingTimeline(multiWindowTimeline, 1);
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333); TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1); TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, for (boolean shuffled : new boolean[] { false, true }) {
C.INDEX_UNSET, 0, 1); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, shuffled,
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2); C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 2, 0, 1); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled,
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, 0, 1, 2);
1, 2, C.INDEX_UNSET); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled,
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2); 2, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 1, 2, 0); TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, shuffled,
1, 2, C.INDEX_UNSET);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
}
} }
public void testMultiLoop() { public void testMultiLoop() {
Timeline timeline = getLoopingTimeline(multiWindowTimeline, 3); Timeline timeline = getLoopingTimeline(multiWindowTimeline, 3);
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333, 111, 222, 333, 111, 222, 333); TimelineAsserts.assertWindowIds(timeline, 111, 222, 333, 111, 222, 333, 111, 222, 333);
TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1, 1, 1, 1, 1, 1, 1); TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1, 1, 1, 1, 1, 1, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, for (boolean shuffled : new boolean[] { false, true }) {
C.INDEX_UNSET, 0, 1, 2, 3, 4, 5, 6, 7, 8); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, shuffled,
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, C.INDEX_UNSET, 0, 1, 2, 3, 4, 5, 6, 7, 8);
0, 1, 2, 3, 4, 5, 6, 7, 8); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled,
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 0, 1, 2, 3, 4, 5, 6, 7, 8);
8, 0, 1, 2, 3, 4, 5, 6, 7); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled,
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, 8, 0, 1, 2, 3, 4, 5, 6, 7);
1, 2, 3, 4, 5, 6, 7, 8, C.INDEX_UNSET); TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, shuffled,
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 1, 2, 3, 4, 5, 6, 7, 8, C.INDEX_UNSET);
0, 1, 2, 3, 4, 5, 6, 7, 8); TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled,
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 0, 1, 2, 3, 4, 5, 6, 7, 8);
1, 2, 3, 4, 5, 6, 7, 8, 0); TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled,
1, 2, 3, 4, 5, 6, 7, 8, 0);
}
} }
public void testInfiniteLoop() { public void testInfiniteLoop() {
Timeline timeline = getLoopingTimeline(multiWindowTimeline, Integer.MAX_VALUE); Timeline timeline = getLoopingTimeline(multiWindowTimeline, Integer.MAX_VALUE);
TimelineAsserts.assertWindowIds(timeline, 111, 222, 333); TimelineAsserts.assertWindowIds(timeline, 111, 222, 333);
TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1); TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, 2, 0, 1); for (boolean shuffled : new boolean[] { false, true }) {
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, shuffled,
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 2, 0, 1); 2, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, 1, 2, 0); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled,
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2); 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 1, 2, 0); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled,
2, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, shuffled, 1, 2, 0);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, shuffled, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, shuffled, 1, 2, 0);
}
} }
/** /**
...@@ -93,3 +104,4 @@ public class LoopingMediaSourceTest extends TestCase { ...@@ -93,3 +104,4 @@ public class LoopingMediaSourceTest extends TestCase {
} }
} }
...@@ -171,7 +171,8 @@ public final class LoopingMediaSource implements MediaSource { ...@@ -171,7 +171,8 @@ public final class LoopingMediaSource implements MediaSource {
boolean shuffleModeEnabled) { boolean shuffleModeEnabled) {
int childNextWindowIndex = timeline.getNextWindowIndex(windowIndex, repeatMode, int childNextWindowIndex = timeline.getNextWindowIndex(windowIndex, repeatMode,
shuffleModeEnabled); shuffleModeEnabled);
return childNextWindowIndex == C.INDEX_UNSET ? 0 : childNextWindowIndex; return childNextWindowIndex == C.INDEX_UNSET ? getFirstWindowIndex(shuffleModeEnabled)
: childNextWindowIndex;
} }
@Override @Override
...@@ -179,7 +180,7 @@ public final class LoopingMediaSource implements MediaSource { ...@@ -179,7 +180,7 @@ public final class LoopingMediaSource implements MediaSource {
boolean shuffleModeEnabled) { boolean shuffleModeEnabled) {
int childPreviousWindowIndex = timeline.getPreviousWindowIndex(windowIndex, repeatMode, int childPreviousWindowIndex = timeline.getPreviousWindowIndex(windowIndex, repeatMode,
shuffleModeEnabled); shuffleModeEnabled);
return childPreviousWindowIndex == C.INDEX_UNSET ? getWindowCount() - 1 return childPreviousWindowIndex == C.INDEX_UNSET ? getLastWindowIndex(shuffleModeEnabled)
: childPreviousWindowIndex; : childPreviousWindowIndex;
} }
......
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