use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class MediaSourceListTest method addMediaSources_mediaSourceListUnprepared_notUsingLazyPreparation_expectUnprepared.
@Test
public void addMediaSources_mediaSourceListUnprepared_notUsingLazyPreparation_expectUnprepared() {
MediaSource mockMediaSource1 = mock(MediaSource.class);
when(mockMediaSource1.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
MediaSource mockMediaSource2 = mock(MediaSource.class);
when(mockMediaSource2.getMediaItem()).thenReturn(MINIMAL_MEDIA_ITEM);
List<MediaSourceList.MediaSourceHolder> mediaSources = createFakeHoldersWithSources(/* useLazyPreparation= */
false, mockMediaSource1, mockMediaSource2);
mediaSourceList.addMediaSources(/* index= */
0, mediaSources, new ShuffleOrder.DefaultShuffleOrder(2));
assertThat(mediaSourceList.getSize()).isEqualTo(2);
// Verify lazy initialization does not call prepare on sources.
verify(mockMediaSource1, times(0)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
verify(mockMediaSource2, times(0)).prepareSource(any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */
isNull(), any());
for (int i = 0; i < mediaSources.size(); i++) {
assertThat(mediaSources.get(i).firstWindowIndexInChild).isEqualTo(i);
assertThat(mediaSources.get(i).isRemoved).isFalse();
}
// Add for more sources in between.
List<MediaSourceList.MediaSourceHolder> moreMediaSources = createFakeHolders();
mediaSourceList.addMediaSources(/* index= */
1, moreMediaSources, new ShuffleOrder.DefaultShuffleOrder(/* length= */
3));
assertThat(mediaSources.get(0).firstWindowIndexInChild).isEqualTo(0);
assertThat(moreMediaSources.get(0).firstWindowIndexInChild).isEqualTo(1);
assertThat(moreMediaSources.get(3).firstWindowIndexInChild).isEqualTo(4);
assertThat(mediaSources.get(1).firstWindowIndexInChild).isEqualTo(5);
}
use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class DefaultAnalyticsCollectorTest method drmEvents_errorHandling.
@Test
public void drmEvents_errorHandling() throws Exception {
BlockingDrmCallback mediaDrmCallback = BlockingDrmCallback.alwaysFailing();
DrmSessionManager failingDrmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm.Builder().setEnforceValidKeyResponses(false).build()).setMultiSession(true).build(mediaDrmCallback);
MediaSource mediaSource = new FakeMediaSource(SINGLE_PERIOD_TIMELINE, failingDrmSessionManager, VIDEO_FORMAT_DRM_1);
TestAnalyticsListener listener = runAnalyticsTest(mediaSource, new ActionSchedule.Builder(TAG).waitForIsLoading(false).executeRunnable(mediaDrmCallback.keyCondition::open).build());
populateEventIds(listener.lastReportedTimeline);
assertThat(listener.getEvents(EVENT_DRM_SESSION_MANAGER_ERROR)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period0);
}
use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class ExoPlayerTest method sendMessagesNonLinearPeriodOrder.
@Test
public void sendMessagesNonLinearPeriodOrder() throws Exception {
Timeline fakeTimeline = new FakeTimeline();
MediaSource[] fakeMediaSources = { new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT), new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT) };
ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(false, new FakeShuffleOrder(3), fakeMediaSources);
PositionGrabbingMessageTarget target1 = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget target2 = new PositionGrabbingMessageTarget();
PositionGrabbingMessageTarget target3 = new PositionGrabbingMessageTarget();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).sendMessage(target1, /* mediaItemIndex = */
0, /* positionMs= */
50).sendMessage(target2, /* mediaItemIndex = */
1, /* positionMs= */
50).sendMessage(target3, /* mediaItemIndex = */
2, /* positionMs= */
50).setShuffleModeEnabled(true).seek(/* mediaItemIndex= */
2, /* positionMs= */
0).play().build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
assertThat(target1.mediaItemIndex).isEqualTo(0);
assertThat(target2.mediaItemIndex).isEqualTo(1);
assertThat(target3.mediaItemIndex).isEqualTo(2);
}
use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class ExoPlayerTest method seekTo_mediaItemIndexIsReset.
@Test
public void seekTo_mediaItemIndexIsReset() throws Exception {
FakeTimeline fakeTimeline = new FakeTimeline();
FakeMediaSource mediaSource = new FakeMediaSource(fakeTimeline);
final int[] mediaItemIndex = { C.INDEX_UNSET };
final long[] positionMs = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
final long[] bufferedPositions = { C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET };
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().seek(/* mediaItemIndex= */
1, /* positionMs= */
C.TIME_UNSET).playUntilPosition(/* mediaItemIndex= */
1, /* positionMs= */
3000).pause().executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
positionMs[0] = player.getCurrentPosition();
bufferedPositions[0] = player.getBufferedPosition();
player.setMediaSource(mediaSource, /* startPositionMs= */
7000);
player.prepare();
positionMs[1] = player.getCurrentPosition();
bufferedPositions[1] = player.getBufferedPosition();
}
}).waitForPlaybackState(Player.STATE_READY).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
mediaItemIndex[0] = player.getCurrentMediaItemIndex();
positionMs[2] = player.getCurrentPosition();
bufferedPositions[2] = player.getBufferedPosition();
}
}).build();
new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource, mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS);
assertThat(mediaItemIndex[0]).isEqualTo(0);
assertThat(positionMs[0]).isAtLeast(3000);
assertThat(positionMs[1]).isEqualTo(7000);
assertThat(positionMs[2]).isEqualTo(7000);
assertThat(bufferedPositions[0]).isAtLeast(3000);
assertThat(bufferedPositions[1]).isEqualTo(7000);
assertThat(bufferedPositions[2]).isEqualTo(fakeTimeline.getWindow(0, new Window()).getDurationMs());
}
use of com.google.android.exoplayer2.source.MediaSource in project ExoPlayer by google.
the class ExoPlayerTest method resetPlaylistStartsFromDefaultPosition.
@Test
public void resetPlaylistStartsFromDefaultPosition() throws Exception {
Object firstWindowId = new Object();
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
firstWindowId));
Timeline firstExpectedPlaceholderTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeTimeline.FAKE_MEDIA_ITEM.buildUpon().setTag(firstWindowId).build());
Object secondWindowId = new Object();
Timeline secondTimeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
secondWindowId));
Timeline secondExpectedPlaceholderTimeline = new MaskingMediaSource.PlaceholderTimeline(FakeTimeline.FAKE_MEDIA_ITEM.buildUpon().setTag(secondWindowId).build());
MediaSource secondSource = new FakeMediaSource(secondTimeline);
AtomicLong positionAfterReprepare = new AtomicLong();
ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).playUntilPosition(/* mediaItemIndex= */
0, /* positionMs= */
2000).setMediaSources(/* resetPosition= */
true, secondSource).waitForTimelineChanged(secondTimeline, /* expectedReason */
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE).executeRunnable(new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
positionAfterReprepare.set(player.getCurrentPosition());
}
}).play().build();
ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setTimeline(timeline).setActionSchedule(actionSchedule).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS);
testRunner.assertTimelinesSame(firstExpectedPlaceholderTimeline, timeline, secondExpectedPlaceholderTimeline, secondTimeline);
testRunner.assertTimelineChangeReasonsEqual(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE, Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
assertThat(positionAfterReprepare.get()).isEqualTo(0L);
}
Aggregations