use of com.google.android.exoplayer2.testutil.FakeClock in project ExoPlayer by google.
the class FakeClockTest method createHandler_sendMessageAtFrontOfQueue_sendsMessageFirst.
@Test
public void createHandler_sendMessageAtFrontOfQueue_sendsMessageFirst() {
HandlerThread handlerThread = new HandlerThread("FakeClockTest");
handlerThread.start();
FakeClock fakeClock = new FakeClock(/* initialTimeMs= */
0);
TestCallback callback = new TestCallback();
HandlerWrapper handler = fakeClock.createHandler(handlerThread.getLooper(), callback);
handler.obtainMessage(/* what= */
1).sendToTarget();
handler.sendMessageAtFrontOfQueue(handler.obtainMessage(/* what= */
2));
handler.sendMessageAtFrontOfQueue(handler.obtainMessage(/* what= */
3));
handler.obtainMessage(/* what= */
4).sendToTarget();
ShadowLooper.idleMainLooper();
shadowOf(handler.getLooper()).idle();
assertThat(callback.messages).containsExactly(new MessageData(/* what= */
3, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null), new MessageData(/* what= */
2, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null), new MessageData(/* what= */
1, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null), new MessageData(/* what= */
4, /* arg1= */
0, /* arg2= */
0, /* obj=*/
null)).inOrder();
}
use of com.google.android.exoplayer2.testutil.FakeClock in project ExoPlayer by google.
the class TransformerEndToEndTest method setUp.
@Before
public void setUp() throws Exception {
context = ApplicationProvider.getApplicationContext();
outputPath = Util.createTempFile(context, "TransformerTest").getPath();
clock = new FakeClock(/* isAutoAdvancing= */
true);
progressHolder = new ProgressHolder();
createEncodersAndDecoders();
}
use of com.google.android.exoplayer2.testutil.FakeClock in project ExoPlayer by google.
the class ExoPlayerTest method targetLiveOffsetInMedia_afterSeekToDefaultPositionInOtherStream_adjustsLiveOffsetToMediaOffset.
@Test
public void targetLiveOffsetInMedia_afterSeekToDefaultPositionInOtherStream_adjustsLiveOffsetToMediaOffset() throws Exception {
long windowStartUnixTimeMs = 987_654_321_000L;
long nowUnixTimeMs = windowStartUnixTimeMs + 20_000;
ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
nowUnixTimeMs, /* isAutoAdvancing= */
true)).build();
Timeline liveTimeline1 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
Timeline liveTimeline2 = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(4_000).build()).build()));
player.pause();
player.addMediaSource(new FakeMediaSource(liveTimeline1));
player.addMediaSource(new FakeMediaSource(liveTimeline2));
// Ensure we override the target live offset to a seek position in the first live stream.
player.seekTo(10_000);
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Seek to default position in second stream.
player.seekToNextMediaItem();
// Play until close to the end of the available live window.
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
1, /* positionMs= */
999_000);
long liveOffsetAtEnd = player.getCurrentLiveOffset();
player.release();
// Assert that player adjusted live offset to the media value.
assertThat(liveOffsetAtEnd).isIn(Range.closed(3_900L, 4_100L));
}
use of com.google.android.exoplayer2.testutil.FakeClock in project ExoPlayer by google.
the class ExoPlayerTest method targetLiveOffsetInMedia_unknownWindowStartTime_doesNotAdjustLiveOffset.
@Test
public void targetLiveOffsetInMedia_unknownWindowStartTime_doesNotAdjustLiveOffset() throws Exception {
FakeClock fakeClock = new FakeClock(/* initialTimeMs= */
987_654_321L, /* isAutoAdvancing= */
true);
ExoPlayer player = new TestExoPlayerBuilder(context).setClock(fakeClock).build();
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(4_000).build()).build();
Timeline liveTimeline = new SinglePeriodTimeline(/* presentationStartTimeMs= */
C.TIME_UNSET, /* windowStartTimeMs= */
C.TIME_UNSET, /* elapsedRealtimeEpochOffsetMs= */
C.TIME_UNSET, /* periodDurationUs= */
1000 * C.MICROS_PER_SECOND, /* windowDurationUs= */
1000 * C.MICROS_PER_SECOND, /* windowPositionInPeriodUs= */
0, /* windowDefaultStartPositionUs= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* suppressPositionProjection= */
false, /* manifest= */
null, mediaItem, mediaItem.liveConfiguration);
player.pause();
player.setMediaSource(new FakeMediaSource(liveTimeline));
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
long playbackStartTimeMs = fakeClock.elapsedRealtime();
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
999_000);
long playbackEndTimeMs = fakeClock.elapsedRealtime();
player.release();
// Assert that the time it took to play 999 seconds of media is 999 seconds (asserting that no
// playback speed adjustment was used).
assertThat(playbackEndTimeMs - playbackStartTimeMs).isEqualTo(999_000);
}
use of com.google.android.exoplayer2.testutil.FakeClock in project ExoPlayer by google.
the class ExoPlayerTest method targetLiveOffsetInMedia_withInitialSeek_adjustsLiveOffsetToInitialSeek.
@Test
public void targetLiveOffsetInMedia_withInitialSeek_adjustsLiveOffsetToInitialSeek() throws Exception {
long windowStartUnixTimeMs = 987_654_321_000L;
long nowUnixTimeMs = windowStartUnixTimeMs + 20_000;
ExoPlayer player = new TestExoPlayerBuilder(context).setClock(new FakeClock(/* initialTimeMs= */
nowUnixTimeMs, /* isAutoAdvancing= */
true)).build();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
1000 * C.MICROS_PER_SECOND, /* defaultPositionUs= */
8 * C.MICROS_PER_SECOND, /* windowOffsetInFirstPeriodUs= */
Util.msToUs(windowStartUnixTimeMs), ImmutableList.of(AdPlaybackState.NONE), new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(9_000).build()).build()));
player.pause();
player.seekTo(18_000);
player.setMediaSource(new FakeMediaSource(timeline), /* resetPosition= */
false);
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
long liveOffsetAtStart = player.getCurrentLiveOffset();
// Play until close to the end of the available live window.
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
999_000);
long liveOffsetAtEnd = player.getCurrentLiveOffset();
player.release();
// Target should have been permanently adjusted to 2 seconds.
// (initial now = 20 seconds in live window, initial seek to 18 seconds)
assertThat(liveOffsetAtStart).isIn(Range.closed(1_900L, 2_100L));
assertThat(liveOffsetAtEnd).isIn(Range.closed(1_900L, 2_100L));
}
Aggregations