mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Simplify timeline test stub class.
Use an actual class for the stub media source instead of an anomymous class. Allows to call assertReleased() on that class. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=159109143
This commit is contained in:
parent
ed27017b0c
commit
023c9d56a9
4 changed files with 47 additions and 29 deletions
|
|
@ -73,37 +73,52 @@ public class TimelineTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a stub {@link MediaSource} with the specified {@link Timeline} in its source info.
|
||||
* Stub media source which returns a provided timeline as source info and keeps track if it is
|
||||
* prepared and released.
|
||||
*/
|
||||
public static MediaSource stubMediaSourceSourceWithTimeline(final Timeline timeline) {
|
||||
return new MediaSource() {
|
||||
@Override
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
listener.onSourceInfoRefreshed(timeline, null);
|
||||
}
|
||||
public static class StubMediaSource implements MediaSource {
|
||||
private final Timeline timeline;
|
||||
|
||||
@Override
|
||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
||||
}
|
||||
private boolean isPrepared;
|
||||
private volatile boolean isReleased;
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
return null;
|
||||
}
|
||||
public StubMediaSource(Timeline timeline) {
|
||||
this.timeline = timeline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releasePeriod(MediaPeriod mediaPeriod) {
|
||||
}
|
||||
@Override
|
||||
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
|
||||
assertFalse(isPrepared);
|
||||
listener.onSourceInfoRefreshed(timeline, null);
|
||||
isPrepared = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releasePeriod(MediaPeriod mediaPeriod) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSource() {
|
||||
assertTrue(isPrepared);
|
||||
isReleased = true;
|
||||
}
|
||||
|
||||
public void assertReleased() {
|
||||
assertTrue(isReleased);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Works in conjunction with {@code stubMediaSourceSourceWithTimeline} to extract the Timeline
|
||||
* from a media source.
|
||||
* Extracts the timeline from a media source.
|
||||
*/
|
||||
public static Timeline extractTimelineFromMediaSource(MediaSource mediaSource) {
|
||||
class TimelineListener implements Listener {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.google.android.exoplayer2.Timeline.Period;
|
|||
import com.google.android.exoplayer2.Timeline.Window;
|
||||
import com.google.android.exoplayer2.TimelineTest;
|
||||
import com.google.android.exoplayer2.TimelineTest.FakeTimeline;
|
||||
import com.google.android.exoplayer2.TimelineTest.StubMediaSource;
|
||||
import com.google.android.exoplayer2.TimelineTest.TimelineVerifier;
|
||||
|
||||
/**
|
||||
|
|
@ -119,7 +120,7 @@ public final class ClippingMediaSourceTest extends InstrumentationTestCase {
|
|||
* Wraps the specified timeline in a {@link ClippingMediaSource} and returns the clipped timeline.
|
||||
*/
|
||||
private static Timeline getClippedTimeline(Timeline timeline, long startMs, long endMs) {
|
||||
MediaSource mediaSource = TimelineTest.stubMediaSourceSourceWithTimeline(timeline);
|
||||
MediaSource mediaSource = new StubMediaSource(timeline);
|
||||
return TimelineTest.extractTimelineFromMediaSource(
|
||||
new ClippingMediaSource(mediaSource, startMs, endMs));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.google.android.exoplayer2.ExoPlayer;
|
|||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.TimelineTest;
|
||||
import com.google.android.exoplayer2.TimelineTest.FakeTimeline;
|
||||
import com.google.android.exoplayer2.TimelineTest.StubMediaSource;
|
||||
import com.google.android.exoplayer2.TimelineTest.TimelineVerifier;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -101,7 +102,7 @@ public final class ConcatenatingMediaSourceTest extends TestCase {
|
|||
Timeline... timelines) {
|
||||
MediaSource[] mediaSources = new MediaSource[timelines.length];
|
||||
for (int i = 0; i < timelines.length; i++) {
|
||||
mediaSources[i] = TimelineTest.stubMediaSourceSourceWithTimeline(timelines[i]);
|
||||
mediaSources[i] = new StubMediaSource(timelines[i]);
|
||||
}
|
||||
return TimelineTest.extractTimelineFromMediaSource(
|
||||
new ConcatenatingMediaSource(isRepeatOneAtomic, mediaSources));
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.google.android.exoplayer2.ExoPlayer;
|
|||
import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.TimelineTest;
|
||||
import com.google.android.exoplayer2.TimelineTest.FakeTimeline;
|
||||
import com.google.android.exoplayer2.TimelineTest.StubMediaSource;
|
||||
import com.google.android.exoplayer2.TimelineTest.TimelineVerifier;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -33,9 +34,9 @@ public class LoopingMediaSourceTest extends TestCase {
|
|||
public LoopingMediaSourceTest() {
|
||||
multiWindowTimeline = TimelineTest.extractTimelineFromMediaSource(
|
||||
new ConcatenatingMediaSource(
|
||||
TimelineTest.stubMediaSourceSourceWithTimeline(new FakeTimeline(1, 111)),
|
||||
TimelineTest.stubMediaSourceSourceWithTimeline(new FakeTimeline(1, 222)),
|
||||
TimelineTest.stubMediaSourceSourceWithTimeline(new FakeTimeline(1, 333))));
|
||||
new StubMediaSource(new FakeTimeline(1, 111)),
|
||||
new StubMediaSource(new FakeTimeline(1, 222)),
|
||||
new StubMediaSource(new FakeTimeline(1, 333))));
|
||||
}
|
||||
|
||||
public void testSingleLoop() {
|
||||
|
|
@ -83,7 +84,7 @@ public class LoopingMediaSourceTest extends TestCase {
|
|||
* the looping timeline.
|
||||
*/
|
||||
private static Timeline getLoopingTimeline(Timeline timeline, int loopCount) {
|
||||
MediaSource mediaSource = TimelineTest.stubMediaSourceSourceWithTimeline(timeline);
|
||||
MediaSource mediaSource = new StubMediaSource(timeline);
|
||||
return TimelineTest.extractTimelineFromMediaSource(
|
||||
new LoopingMediaSource(mediaSource, loopCount));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue