mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix flaky test case
PiperOrigin-RevId: 347987861
This commit is contained in:
parent
d9c058c60a
commit
8a560429e9
1 changed files with 58 additions and 15 deletions
|
|
@ -7536,14 +7536,54 @@ public final class ExoPlayerTest {
|
||||||
.isEqualTo(rendererStreamOffsetsUs.get(0) + periodDurationUs);
|
.isEqualTo(rendererStreamOffsetsUs.get(0) + periodDurationUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore // See [internal: b/175773664]
|
|
||||||
@Test
|
@Test
|
||||||
public void mediaItemOfSources_correctInTimelineWindows() throws Exception {
|
public void mediaItemOfSources_correctInTimelineWindows() throws Exception {
|
||||||
SilenceMediaSource.Factory factory =
|
TimelineWindowDefinition window1 =
|
||||||
new SilenceMediaSource.Factory().setDurationUs(C.msToUs(100_000));
|
new TimelineWindowDefinition(
|
||||||
|
/* periodCount= */ 1,
|
||||||
|
/* id= */ 1,
|
||||||
|
/* isSeekable= */ true,
|
||||||
|
/* isDynamic= */ false,
|
||||||
|
/* isLive= */ false,
|
||||||
|
/* isPlaceholder= */ false,
|
||||||
|
/* durationUs = */ 100_000,
|
||||||
|
/* defaultPositionUs = */ 0,
|
||||||
|
/* windowOffsetInFirstPeriodUs= */ 0,
|
||||||
|
AdPlaybackState.NONE,
|
||||||
|
MediaItem.fromUri("http://foo.bar/fake1"));
|
||||||
|
FakeMediaSource fakeMediaSource1 = new FakeMediaSource(new FakeTimeline(window1));
|
||||||
|
TimelineWindowDefinition window2 =
|
||||||
|
new TimelineWindowDefinition(
|
||||||
|
/* periodCount= */ 1,
|
||||||
|
/* id= */ 2,
|
||||||
|
/* isSeekable= */ true,
|
||||||
|
/* isDynamic= */ false,
|
||||||
|
/* isLive= */ false,
|
||||||
|
/* isPlaceholder= */ false,
|
||||||
|
/* durationUs = */ 100_000,
|
||||||
|
/* defaultPositionUs = */ 0,
|
||||||
|
/* windowOffsetInFirstPeriodUs= */ 0,
|
||||||
|
AdPlaybackState.NONE,
|
||||||
|
MediaItem.fromUri("http://foo.bar/fake2"));
|
||||||
|
FakeMediaSource fakeMediaSource2 = new FakeMediaSource(new FakeTimeline(window2));
|
||||||
|
TimelineWindowDefinition window3 =
|
||||||
|
new TimelineWindowDefinition(
|
||||||
|
/* periodCount= */ 1,
|
||||||
|
/* id= */ 3,
|
||||||
|
/* isSeekable= */ true,
|
||||||
|
/* isDynamic= */ false,
|
||||||
|
/* isLive= */ false,
|
||||||
|
/* isPlaceholder= */ false,
|
||||||
|
/* durationUs = */ 100_000,
|
||||||
|
/* defaultPositionUs = */ 0,
|
||||||
|
/* windowOffsetInFirstPeriodUs= */ 0,
|
||||||
|
AdPlaybackState.NONE,
|
||||||
|
MediaItem.fromUri("http://foo.bar/fake3"));
|
||||||
|
FakeMediaSource fakeMediaSource3 = new FakeMediaSource(new FakeTimeline(window3));
|
||||||
final Player[] playerHolder = {null};
|
final Player[] playerHolder = {null};
|
||||||
ActionSchedule actionSchedule =
|
ActionSchedule actionSchedule =
|
||||||
new ActionSchedule.Builder(TAG)
|
new ActionSchedule.Builder(TAG)
|
||||||
|
.pause()
|
||||||
.executeRunnable(
|
.executeRunnable(
|
||||||
new PlayerRunnable() {
|
new PlayerRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -7553,10 +7593,10 @@ public final class ExoPlayerTest {
|
||||||
})
|
})
|
||||||
.waitForPlaybackState(Player.STATE_READY)
|
.waitForPlaybackState(Player.STATE_READY)
|
||||||
.seek(/* positionMs= */ 0)
|
.seek(/* positionMs= */ 0)
|
||||||
.waitForPlaybackState(Player.STATE_ENDED)
|
.play()
|
||||||
.build();
|
.build();
|
||||||
List<MediaItem> currentMediaItems = new ArrayList<>();
|
List<MediaItem> currentMediaItems = new ArrayList<>();
|
||||||
List<MediaItem> initialMediaItems = new ArrayList<>();
|
List<MediaItem> mediaItemsInTimeline = new ArrayList<>();
|
||||||
Player.EventListener eventListener =
|
Player.EventListener eventListener =
|
||||||
new Player.EventListener() {
|
new Player.EventListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -7566,31 +7606,34 @@ public final class ExoPlayerTest {
|
||||||
}
|
}
|
||||||
Window window = new Window();
|
Window window = new Window();
|
||||||
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
for (int i = 0; i < timeline.getWindowCount(); i++) {
|
||||||
initialMediaItems.add(timeline.getWindow(i, window).mediaItem);
|
mediaItemsInTimeline.add(timeline.getWindow(i, window).mediaItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPositionDiscontinuity(int reason) {
|
public void onPositionDiscontinuity(int reason) {
|
||||||
currentMediaItems.add(playerHolder[0].getCurrentMediaItem());
|
if (reason == Player.DISCONTINUITY_REASON_SEEK
|
||||||
|
|| reason == Player.DISCONTINUITY_REASON_PERIOD_TRANSITION) {
|
||||||
|
currentMediaItems.add(playerHolder[0].getCurrentMediaItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
new ExoPlayerTestRunner.Builder(context)
|
new ExoPlayerTestRunner.Builder(context)
|
||||||
.setEventListener(eventListener)
|
.setEventListener(eventListener)
|
||||||
.setActionSchedule(actionSchedule)
|
.setActionSchedule(actionSchedule)
|
||||||
.setMediaSources(
|
.setMediaSources(fakeMediaSource1, fakeMediaSource2, fakeMediaSource3)
|
||||||
factory.setTag("1").createMediaSource(),
|
|
||||||
factory.setTag("2").createMediaSource(),
|
|
||||||
factory.setTag("3").createMediaSource())
|
|
||||||
.build()
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.blockUntilActionScheduleFinished(TIMEOUT_MS)
|
.blockUntilActionScheduleFinished(TIMEOUT_MS)
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.blockUntilEnded(TIMEOUT_MS);
|
||||||
|
|
||||||
assertThat(currentMediaItems.get(0).playbackProperties.tag).isEqualTo("1");
|
assertThat(currentMediaItems.get(0).playbackProperties.uri.toString())
|
||||||
assertThat(currentMediaItems.get(1).playbackProperties.tag).isEqualTo("2");
|
.isEqualTo("http://foo.bar/fake1");
|
||||||
assertThat(currentMediaItems.get(2).playbackProperties.tag).isEqualTo("3");
|
assertThat(currentMediaItems.get(1).playbackProperties.uri.toString())
|
||||||
assertThat(initialMediaItems).containsExactlyElementsIn(currentMediaItems);
|
.isEqualTo("http://foo.bar/fake2");
|
||||||
|
assertThat(currentMediaItems.get(2).playbackProperties.uri.toString())
|
||||||
|
.isEqualTo("http://foo.bar/fake3");
|
||||||
|
assertThat(mediaItemsInTimeline).containsExactlyElementsIn(currentMediaItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue