@Override public int getLastWindowIndex(boolean shuffleModeEnabled) { return timeline.getLastWindowIndex(shuffleModeEnabled); }
/** * Returns the index of the window after the window at index {@code windowIndex} depending on the * {@code repeatMode} and whether shuffling is enabled. * * @param windowIndex Index of a window in the timeline. * @param repeatMode A repeat mode. * @param shuffleModeEnabled Whether shuffling is enabled. * @return The index of the next window, or {@link C#INDEX_UNSET} if this is the last window. */ public int getNextWindowIndex(int windowIndex, @Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) { switch (repeatMode) { case Player.REPEAT_MODE_OFF: return windowIndex == getLastWindowIndex(shuffleModeEnabled) ? C.INDEX_UNSET : windowIndex + 1; case Player.REPEAT_MODE_ONE: return windowIndex; case Player.REPEAT_MODE_ALL: return windowIndex == getLastWindowIndex(shuffleModeEnabled) ? getFirstWindowIndex(shuffleModeEnabled) : windowIndex + 1; default: throw new IllegalStateException(); } }
/** * Returns the index of the window before the window at index {@code windowIndex} depending on the * {@code repeatMode} and whether shuffling is enabled. * * @param windowIndex Index of a window in the timeline. * @param repeatMode A repeat mode. * @param shuffleModeEnabled Whether shuffling is enabled. * @return The index of the previous window, or {@link C#INDEX_UNSET} if this is the first window. */ public int getPreviousWindowIndex(int windowIndex, @Player.RepeatMode int repeatMode, boolean shuffleModeEnabled) { switch (repeatMode) { case Player.REPEAT_MODE_OFF: return windowIndex == getFirstWindowIndex(shuffleModeEnabled) ? C.INDEX_UNSET : windowIndex - 1; case Player.REPEAT_MODE_ONE: return windowIndex; case Player.REPEAT_MODE_ALL: return windowIndex == getFirstWindowIndex(shuffleModeEnabled) ? getLastWindowIndex(shuffleModeEnabled) : windowIndex - 1; default: throw new IllegalStateException(); } }
/** Assert that timeline is empty (i.e. has no windows or periods). */ public static void assertEmpty(Timeline timeline) { assertWindowTags(timeline); assertPeriodCounts(timeline); for (boolean shuffled : new boolean[] {false, true}) { assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET); assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET); } }
/** Assert that timeline is empty (i.e. has no windows or periods). */ public static void assertEmpty(Timeline timeline) { assertWindowTags(timeline); assertPeriodCounts(timeline); for (boolean shuffled : new boolean[] {false, true}) { assertThat(timeline.getFirstWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET); assertThat(timeline.getLastWindowIndex(shuffled)).isEqualTo(C.INDEX_UNSET); } }
@Override public int getLastWindowIndex(boolean shuffleModeEnabled) { if (childCount == 0) { return C.INDEX_UNSET; } if (isAtomic) { shuffleModeEnabled = false; } // Find last non-empty child. int lastChildIndex = shuffleModeEnabled ? shuffleOrder.getLastIndex() : childCount - 1; while (getTimelineByChildIndex(lastChildIndex).isEmpty()) { lastChildIndex = getPreviousChildIndex(lastChildIndex, shuffleModeEnabled); if (lastChildIndex == C.INDEX_UNSET) { // All children are empty. return C.INDEX_UNSET; } } return getFirstWindowIndexByChildIndex(lastChildIndex) + getTimelineByChildIndex(lastChildIndex).getLastWindowIndex(shuffleModeEnabled); }
+ getTimelineByChildIndex(previousChildIndex).getLastWindowIndex(shuffleModeEnabled);
assertThat(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */ false)).isEqualTo(0); assertThat(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */ true)).isEqualTo(0); assertThat(timeline.getLastWindowIndex(/* shuffleModeEnabled= */ false)).isEqualTo(2); assertThat(timeline.getLastWindowIndex(/* shuffleModeEnabled= */ true)).isEqualTo(2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1); assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0); assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2); assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2); assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0); testRunner.assertPrepareAndReleaseAllPeriods(); testRunner.assertCompletedManifestLoads(0, 1, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 2, 0, 1); assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0); assertThat(timeline.getLastWindowIndex(false)).isEqualTo(timeline.getWindowCount() - 1); TimelineAsserts.assertNextWindowIndices( timeline, Player.REPEAT_MODE_OFF, true, C.INDEX_UNSET, 0, 1); TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 1, 2, 0); assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(timeline.getWindowCount() - 1); assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);