use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.
the class ExoPlayerTest method setRepeatMode_one_doesNotNotifyAvailableCommandsChanged.
@Test
public void setRepeatMode_one_doesNotNotifyAvailableCommandsChanged() {
Player.Commands defaultCommands = createWithDefaultCommands();
Player.Listener mockListener = mock(Player.Listener.class);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.addListener(mockListener);
player.addMediaSource(new FakeMediaSource());
verify(mockListener).onAvailableCommandsChanged(defaultCommands);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
verify(mockListener).onAvailableCommandsChanged(any());
}
use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.
the class ExoPlayerTest method shortAdFollowedByUnpreparedAd_playbackDoesNotGetStuck.
@Test
public void shortAdFollowedByUnpreparedAd_playbackDoesNotGetStuck() throws Exception {
AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
2, /* adGroupTimesUs...= */
0);
long shortAdDurationMs = 1_000;
adPlaybackState = adPlaybackState.withAdDurationsUs(new long[][] { { shortAdDurationMs, shortAdDurationMs } });
Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
false, /* durationUs= */
Util.msToUs(10000), adPlaybackState));
// Simulate the second ad not being prepared.
FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT) {
@Override
protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
return new FakeMediaPeriod(trackGroupArray, allocator, FakeMediaPeriod.TrackDataFactory.singleSampleWithTimeUs(0), mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
id.adIndexInAdGroup == 1);
}
};
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.setMediaSource(mediaSource);
player.prepare();
player.play();
// The player is not stuck in the buffering state.
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
}
use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.
the class ExoPlayerTest method seekForward_callsOnPositionDiscontinuity.
@Test
public void seekForward_callsOnPositionDiscontinuity() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener listener = mock(Player.Listener.class);
player.addListener(listener);
Timeline fakeTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
true, /* isDynamic= */
true, /* durationUs= */
Util.msToUs(2 * C.DEFAULT_SEEK_FORWARD_INCREMENT_MS)));
player.setMediaSource(new FakeMediaSource(fakeTimeline));
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
player.seekForward();
ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
verify(listener, never()).onPositionDiscontinuity(any(), any(), not(eq(Player.DISCONTINUITY_REASON_SEEK)));
verify(listener).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_SEEK));
List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
List<Player.PositionInfo> newPositions = newPosition.getAllValues();
assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(0).positionMs).isEqualTo(0);
assertThat(oldPositions.get(0).contentPositionMs).isEqualTo(0);
assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(0).positionMs).isEqualTo(C.DEFAULT_SEEK_FORWARD_INCREMENT_MS);
assertThat(newPositions.get(0).contentPositionMs).isEqualTo(C.DEFAULT_SEEK_FORWARD_INCREMENT_MS);
player.release();
}
use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.
the class ExoPlayerTest method seekTo_callsOnPositionDiscontinuity.
@Test
public void seekTo_callsOnPositionDiscontinuity() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener listener = mock(Player.Listener.class);
player.addListener(listener);
player.setMediaSources(ImmutableList.of(createFakeMediaSource(/* id= */
"id-0"), createFakeMediaSource(/* id= */
"id-1")));
player.prepare();
TestPlayerRunHelper.playUntilPosition(player, /* mediaItemIndex= */
0, /* positionMs= */
5 * C.MILLIS_PER_SECOND);
player.seekTo(/* positionMs= */
7 * C.MILLIS_PER_SECOND);
player.seekTo(/* mediaItemIndex= */
1, /* positionMs= */
C.MILLIS_PER_SECOND);
player.play();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_ENDED);
ArgumentCaptor<Player.PositionInfo> oldPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
ArgumentCaptor<Player.PositionInfo> newPosition = ArgumentCaptor.forClass(Player.PositionInfo.class);
verify(listener, never()).onPositionDiscontinuity(any(), any(), not(eq(Player.DISCONTINUITY_REASON_SEEK)));
verify(listener, times(2)).onPositionDiscontinuity(oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_SEEK));
List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
List<Player.PositionInfo> newPositions = newPosition.getAllValues();
assertThat(oldPositions.get(0).windowUid).isEqualTo(newPositions.get(0).windowUid);
assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(0).mediaItem.localConfiguration.tag).isEqualTo("id-0");
assertThat(oldPositions.get(0).positionMs).isIn(Range.closed(4980L, 5000L));
assertThat(oldPositions.get(0).contentPositionMs).isIn(Range.closed(4980L, 5000L));
assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(0).mediaItem.localConfiguration.tag).isEqualTo("id-0");
assertThat(newPositions.get(0).positionMs).isEqualTo(7_000);
assertThat(newPositions.get(0).contentPositionMs).isEqualTo(7_000);
assertThat(oldPositions.get(1).windowUid).isNotEqualTo(newPositions.get(1).windowUid);
assertThat(oldPositions.get(1).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(1).mediaItem.localConfiguration.tag).isEqualTo("id-0");
assertThat(oldPositions.get(1).positionMs).isEqualTo(7_000);
assertThat(oldPositions.get(1).contentPositionMs).isEqualTo(7_000);
assertThat(newPositions.get(1).mediaItemIndex).isEqualTo(1);
assertThat(newPositions.get(1).mediaItem.localConfiguration.tag).isEqualTo("id-1");
assertThat(newPositions.get(1).positionMs).isEqualTo(1_000);
assertThat(newPositions.get(1).contentPositionMs).isEqualTo(1_000);
player.release();
}
use of com.google.android.exoplayer2.testutil.TestExoPlayerBuilder in project ExoPlayer by google.
the class ExoPlayerTest method onPlaylistMetadataChanged_calledWhenPlaylistMetadataSet.
@Test
public void onPlaylistMetadataChanged_calledWhenPlaylistMetadataSet() {
ExoPlayer player = new TestExoPlayerBuilder(ApplicationProvider.getApplicationContext()).build();
Player.Listener playerListener = mock(Player.Listener.class);
player.addListener(playerListener);
AnalyticsListener analyticsListener = mock(AnalyticsListener.class);
player.addAnalyticsListener(analyticsListener);
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle("test").build();
player.setPlaylistMetadata(mediaMetadata);
verify(playerListener).onPlaylistMetadataChanged(mediaMetadata);
verify(analyticsListener).onPlaylistMetadataChanged(any(), eq(mediaMetadata));
}
Aggregations