use of com.google.android.exoplayer2.source.ClippingMediaSource in project ExoPlayer by google.
the class ExoPlayerTest method seekToUnpreparedWindowWithNonZeroOffsetInConcatenationStartsAtCorrectPosition.
@Test
public void seekToUnpreparedWindowWithNonZeroOffsetInConcatenationStartsAtCorrectPosition() throws Exception {
FakeMediaSource mediaSource = new FakeMediaSource(/* timeline= */
null);
MediaSource clippedMediaSource = new ClippingMediaSource(mediaSource, /* startPositionUs= */
3 * C.MICROS_PER_SECOND, /* endPositionUs= */
C.TIME_END_OF_SOURCE);
MediaSource concatenatedMediaSource = new ConcatenatingMediaSource(clippedMediaSource);
AtomicLong positionWhenReady = new AtomicLong();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_BUFFERING).seek(/* positionMs= */
10).waitForPendingPlayerCommands().executeRunnable(() -> mediaSource.setNewSourceInfo(new FakeTimeline())).waitForTimelineChanged().waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
positionWhenReady.set(player.getContentPosition());
}
}).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(concatenatedMediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(positionWhenReady.get()).isEqualTo(10);
}
use of com.google.android.exoplayer2.source.ClippingMediaSource in project Signal-Android by WhisperSystems.
the class VideoPlayer method clip.
public void clip(long fromUs, long toUs, boolean playWhenReady) {
if (this.exoPlayer != null && mediaItem != null) {
MediaSource mediaItemSource = mediaSourceFactory.createMediaSource(mediaItem);
ClippingMediaSource clippedSource = new ClippingMediaSource(mediaItemSource, fromUs, toUs);
exoPlayer.setMediaSource(clippedSource);
exoPlayer.prepare();
exoPlayer.setPlayWhenReady(playWhenReady);
clipped = true;
clippedStartUs = fromUs;
}
}
Aggregations