CompositeSequenceableLoader implements SequenceableLoader { @Override public boolean continueLoading(long positionUs) { boolean madeProgress = false; boolean madeProgressThisIteration; do { madeProgressThisIteration = false; long nextLoadPositionUs = getNextLoadPositionUs(); if (nextLoadPositionUs == C.TIME_END_OF_SOURCE) { break; } for (SequenceableLoader loader : loaders) { long loaderNextLoadPositionUs = loader.getNextLoadPositionUs(); boolean isLoaderBehind = loaderNextLoadPositionUs != C.TIME_END_OF_SOURCE && loaderNextLoadPositionUs <= positionUs; if (loaderNextLoadPositionUs == nextLoadPositionUs || isLoaderBehind) { madeProgressThisIteration |= loader.continueLoading(positionUs); } } madeProgress |= madeProgressThisIteration; } while (madeProgressThisIteration); return madeProgress; } CompositeSequenceableLoader(SequenceableLoader[] loaders); @Override final long getBufferedPositionUs(); @Override final long getNextLoadPositionUs(); @Override final void reevaluateBuffer(long positionUs); @Override boolean continueLoading(long positionUs); @Override boolean isLoading();  }
@Test public void testContinueLoadingOnlyAllowFurthestBehindLoaderToLoadIfNotBehindPlaybackPosition() { FakeSequenceableLoader loader1 = new FakeSequenceableLoader( 1000, 2000); FakeSequenceableLoader loader2 = new FakeSequenceableLoader( 1001, 2001); CompositeSequenceableLoader compositeSequenceableLoader = new CompositeSequenceableLoader( new SequenceableLoader[] {loader1, loader2}); compositeSequenceableLoader.continueLoading(100); assertThat(loader1.numInvocations).isEqualTo(1); assertThat(loader2.numInvocations).isEqualTo(0); }
@Test public void testContinueLoadingReturnAllowAllLoadersBehindPlaybackPositionToLoad() { FakeSequenceableLoader loader1 = new FakeSequenceableLoader( 1000, 2000); FakeSequenceableLoader loader2 = new FakeSequenceableLoader( 1001, 2001); FakeSequenceableLoader loader3 = new FakeSequenceableLoader( 1002, 2002); CompositeSequenceableLoader compositeSequenceableLoader = new CompositeSequenceableLoader( new SequenceableLoader[] {loader1, loader2, loader3}); compositeSequenceableLoader.continueLoading(3000); assertThat(loader1.numInvocations).isEqualTo(1); assertThat(loader2.numInvocations).isEqualTo(1); assertThat(loader3.numInvocations).isEqualTo(1); }
@Test public void testContinueLoadingOnlyNotAllowEndOfSourceLoaderToLoad() { FakeSequenceableLoader loader1 = new FakeSequenceableLoader( 1000, C.TIME_END_OF_SOURCE); FakeSequenceableLoader loader2 = new FakeSequenceableLoader( 1001, C.TIME_END_OF_SOURCE); CompositeSequenceableLoader compositeSequenceableLoader = new CompositeSequenceableLoader( new SequenceableLoader[] {loader1, loader2}); compositeSequenceableLoader.continueLoading(3000); assertThat(loader1.numInvocations).isEqualTo(0); assertThat(loader2.numInvocations).isEqualTo(0); }
@Test public void testContinueLoadingReturnTrueIfFurthestBehindLoaderCanMakeProgress() { FakeSequenceableLoader loader1 = new FakeSequenceableLoader( 1000, 2000); FakeSequenceableLoader loader2 = new FakeSequenceableLoader( 1001, 2001); loader1.setNextChunkDurationUs(1000); CompositeSequenceableLoader compositeSequenceableLoader = new CompositeSequenceableLoader( new SequenceableLoader[] {loader1, loader2}); assertThat(compositeSequenceableLoader.continueLoading(100)).isTrue(); }
@Test public void testContinueLoadingReturnTrueIfLoaderBehindPlaybackPositionCanMakeProgress() { FakeSequenceableLoader loader1 = new FakeSequenceableLoader( 1000, 2000); FakeSequenceableLoader loader2 = new FakeSequenceableLoader( 1001, 2001); loader2.setNextChunkDurationUs(1000); CompositeSequenceableLoader compositeSequenceableLoader = new CompositeSequenceableLoader( new SequenceableLoader[] {loader1, loader2}); assertThat(compositeSequenceableLoader.continueLoading(3000)).isTrue(); }