use of org.powerbot.script.rt4.Player in project ExoPlayer by google.
the class TestPlayerRunHelper method runUntilPositionDiscontinuity.
/**
* Runs tasks of the main {@link Looper} until {@link
* Player.Listener#onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)} is
* called with the specified {@link Player.DiscontinuityReason} or a playback error occurs.
*
* <p>If a playback error occurs it will be thrown wrapped in an {@link IllegalStateException}.
*
* @param player The {@link Player}.
* @param expectedReason The expected {@link Player.DiscontinuityReason}.
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
* exceeded.
*/
public static void runUntilPositionDiscontinuity(Player player, @Player.DiscontinuityReason int expectedReason) throws TimeoutException {
verifyMainTestThread(player);
AtomicBoolean receivedCallback = new AtomicBoolean(false);
Player.Listener listener = new Player.Listener() {
@Override
public void onPositionDiscontinuity(Player.PositionInfo oldPosition, Player.PositionInfo newPosition, int reason) {
if (reason == expectedReason) {
receivedCallback.set(true);
}
}
};
player.addListener(listener);
runMainLooperUntil(() -> receivedCallback.get() || player.getPlayerError() != null);
player.removeListener(listener);
if (player.getPlayerError() != null) {
throw new IllegalStateException(player.getPlayerError());
}
}
use of org.powerbot.script.rt4.Player in project ExoPlayer by google.
the class PlaybackStatsListenerTest method playerRelease_callsAllPendingCallbacks.
@Test
public void playerRelease_callsAllPendingCallbacks() throws Exception {
PlaybackStatsListener.Callback callback = mock(PlaybackStatsListener.Callback.class);
PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
true, callback);
player.addAnalyticsListener(playbackStatsListener);
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount= */
1));
player.setMediaSources(ImmutableList.of(mediaSource, mediaSource));
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Play close to the end of the first item to ensure the second session is already created, but
// the first one isn't finished yet.
TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */
0, /* positionMs= */
player.getDuration());
runUntilPendingCommandsAreFullyHandled(player);
player.release();
ShadowLooper.idleMainLooper();
ArgumentCaptor<AnalyticsListener.EventTime> eventTimeCaptor = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
verify(callback, times(2)).onPlaybackStatsReady(eventTimeCaptor.capture(), any());
assertThat(eventTimeCaptor.getAllValues().stream().map(eventTime -> eventTime.windowIndex).collect(Collectors.toList())).containsExactly(0, 1);
}
use of org.powerbot.script.rt4.Player in project ExoPlayer by google.
the class PlaybackStatsListenerTest method playlistClear_callsAllPendingCallbacks.
@Test
public void playlistClear_callsAllPendingCallbacks() throws Exception {
PlaybackStatsListener.Callback callback = mock(PlaybackStatsListener.Callback.class);
PlaybackStatsListener playbackStatsListener = new PlaybackStatsListener(/* keepHistory= */
true, callback);
player.addAnalyticsListener(playbackStatsListener);
MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(/* windowCount= */
1));
player.setMediaSources(ImmutableList.of(mediaSource, mediaSource));
player.prepare();
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
// Play close to the end of the first item to ensure the second session is already created, but
// the first one isn't finished yet.
TestPlayerRunHelper.playUntilPosition(player, /* windowIndex= */
0, /* positionMs= */
player.getDuration());
runUntilPendingCommandsAreFullyHandled(player);
player.clearMediaItems();
ShadowLooper.idleMainLooper();
ArgumentCaptor<AnalyticsListener.EventTime> eventTimeCaptor = ArgumentCaptor.forClass(AnalyticsListener.EventTime.class);
verify(callback, times(2)).onPlaybackStatsReady(eventTimeCaptor.capture(), any());
assertThat(eventTimeCaptor.getAllValues().stream().map(eventTime -> eventTime.windowIndex).collect(Collectors.toList())).containsExactly(0, 1);
}
use of org.powerbot.script.rt4.Player in project ExoPlayer by google.
the class CastPlayerTest method autoTransition_notifiesPositionDiscontinuity.
@Test
// Mocks deprecated method used by the CastPlayer.
@SuppressWarnings("deprecation")
public void autoTransition_notifiesPositionDiscontinuity() {
int[] mediaQueueItemIds = new int[] { 1, 2 };
int[] streamTypes = { MediaInfo.STREAM_TYPE_BUFFERED, MediaInfo.STREAM_TYPE_BUFFERED };
long[] durationsFirstMs = { 12500, C.TIME_UNSET };
// When the remote Cast player transitions to an item that wasn't played before, the media state
// delivers the duration for that media item which updates the timeline accordingly.
long[] durationsSecondMs = { 12500, 22000 };
List<MediaItem> mediaItems = createMediaItems(mediaQueueItemIds);
castPlayer.addMediaItems(mediaItems);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
1, /* streamTypes= */
streamTypes, /* durationsMs= */
durationsFirstMs, /* positionMs= */
C.TIME_UNSET);
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */
2, /* streamTypes= */
streamTypes, /* durationsMs= */
durationsSecondMs, /* positionMs= */
C.TIME_UNSET);
Player.PositionInfo oldPosition = new Player.PositionInfo(/* windowUid= */
1, /* windowIndex= */
0, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(), /* periodUid= */
1, /* periodIndex= */
0, /* positionMs= */
12500, /* contentPositionMs= */
12500, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
Player.PositionInfo newPosition = new Player.PositionInfo(/* windowUid= */
2, /* windowIndex= */
1, new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(), /* periodUid= */
2, /* periodIndex= */
1, /* positionMs= */
0, /* contentPositionMs= */
0, /* adGroupIndex= */
C.INDEX_UNSET, /* adIndexInAdGroup= */
C.INDEX_UNSET);
InOrder inOrder = Mockito.inOrder(mockListener);
inOrder.verify(mockListener).onPositionDiscontinuity(eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
inOrder.verify(mockListener).onPositionDiscontinuity(eq(oldPosition), eq(newPosition), eq(Player.DISCONTINUITY_REASON_AUTO_TRANSITION));
inOrder.verify(mockListener, never()).onPositionDiscontinuity(anyInt());
inOrder.verify(mockListener, never()).onPositionDiscontinuity(any(), any(), anyInt());
}
use of org.powerbot.script.rt4.Player in project ExoPlayer by google.
the class AdTagLoader method onTimelineChanged.
// Player.Listener implementation.
@Override
public void onTimelineChanged(Timeline timeline, @Player.TimelineChangeReason int reason) {
if (timeline.isEmpty()) {
// The player is being reset or contains no media.
return;
}
this.timeline = timeline;
Player player = checkNotNull(this.player);
long contentDurationUs = timeline.getPeriod(player.getCurrentPeriodIndex(), period).durationUs;
contentDurationMs = Util.usToMs(contentDurationUs);
if (contentDurationUs != adPlaybackState.contentDurationUs) {
adPlaybackState = adPlaybackState.withContentDurationUs(contentDurationUs);
updateAdPlaybackState();
}
long contentPositionMs = getContentPeriodPositionMs(player, timeline, period);
maybeInitializeAdsManager(contentPositionMs, contentDurationMs);
handleTimelineOrPositionChanged();
}
Aggregations