@Override public void seekTo(long positionMs) { controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), positionMs); }
private void seekTo(long positionMs) { seekTo(player.getCurrentWindowIndex(), positionMs); }
private void updateCurrentItemIndex() { int playbackState = currentPlayer.getPlaybackState(); maybeSetCurrentItemAndNotify( playbackState != Player.STATE_IDLE && playbackState != Player.STATE_ENDED ? currentPlayer.getCurrentWindowIndex() : C.INDEX_UNSET); }
@Override public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) { if (currentWindowIndex != player.getCurrentWindowIndex()) { if (queueNavigator != null) { queueNavigator.onCurrentWindowIndexChanged(player); } currentWindowIndex = player.getCurrentWindowIndex(); // Update playback state after queueNavigator.onCurrentWindowIndexChanged has been called // and before updating metadata. invalidateMediaSessionPlaybackState(); invalidateMediaSessionMetadata(); return; } invalidateMediaSessionPlaybackState(); }
long increment = ACTION_FAST_FORWARD.equals(action) ? fastForwardMs : -rewindMs; controlDispatcher.dispatchSeekTo( player, player.getCurrentWindowIndex(), player.getCurrentPosition() + increment); } else if (ACTION_NEXT.equals(action)) { int nextWindowIndex = player.getNextWindowIndex(); player.getCurrentTimeline().getWindow(player.getCurrentWindowIndex(), window); int previousWindowIndex = player.getPreviousWindowIndex(); if (previousWindowIndex != C.INDEX_UNSET controlDispatcher.dispatchSeekTo(player, previousWindowIndex, C.TIME_UNSET); } else { controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET);
private void publishFloatingQueueWindow(Player player) { if (player.getCurrentTimeline().isEmpty()) { mediaSession.setQueue(Collections.emptyList()); activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID; return; } int windowCount = player.getCurrentTimeline().getWindowCount(); int currentWindowIndex = player.getCurrentWindowIndex(); int queueSize = Math.min(maxQueueSize, windowCount); int startIndex = Util.constrainValue(currentWindowIndex - ((queueSize - 1) / 2), 0, windowCount - queueSize); List<MediaSessionCompat.QueueItem> queue = new ArrayList<>(); for (int i = startIndex; i < startIndex + queueSize; i++) { queue.add(new MediaSessionCompat.QueueItem(getMediaDescription(player, i), i)); } mediaSession.setQueue(queue); activeQueueItemId = currentWindowIndex; }
private EventTime generateEventTime(@Nullable MediaPeriodInfo mediaPeriodInfo) { Assertions.checkNotNull(player); if (mediaPeriodInfo == null) { int windowIndex = player.getCurrentWindowIndex(); mediaPeriodInfo = mediaPeriodQueueTracker.tryResolveWindowIndex(windowIndex); if (mediaPeriodInfo == null) { Timeline timeline = player.getCurrentTimeline(); boolean windowIsInTimeline = windowIndex < timeline.getWindowCount(); return generateEventTime( windowIsInTimeline ? timeline : Timeline.EMPTY, windowIndex, /* mediaPeriodId= */ null); } } return generateEventTime( mediaPeriodInfo.timeline, mediaPeriodInfo.windowIndex, mediaPeriodInfo.mediaPeriodId); }
@Override public void onTimelineChanged( Timeline timeline, @Nullable Object manifest, @Player.TimelineChangeReason int reason) { int windowCount = player.getCurrentTimeline().getWindowCount(); int windowIndex = player.getCurrentWindowIndex(); if (queueNavigator != null) { queueNavigator.onTimelineChanged(player); invalidateMediaSessionPlaybackState(); } else if (currentWindowCount != windowCount || currentWindowIndex != windowIndex) { // active queue item and queue navigation actions may need to be updated invalidateMediaSessionPlaybackState(); } currentWindowCount = windowCount; currentWindowIndex = windowIndex; invalidateMediaSessionMetadata(); }
@Override public final void onCurrentWindowIndexChanged(Player player) { if (activeQueueItemId == MediaSessionCompat.QueueItem.UNKNOWN_ID || player.getCurrentTimeline().getWindowCount() > maxQueueSize) { publishFloatingQueueWindow(player); } else if (!player.getCurrentTimeline().isEmpty()) { activeQueueItemId = player.getCurrentWindowIndex(); } }
@Override public void onCurrentWindowIndexChanged(Player player) { if (activeQueueItemId == MediaSessionCompat.QueueItem.UNKNOWN_ID || player.getCurrentTimeline().getWindowCount() > maxQueueSize) { publishFloatingQueueWindow(); } else if (!player.getCurrentTimeline().isEmpty()) { activeQueueItemId = player.getCurrentWindowIndex(); } }
@Override public void play() { if (player.getPlaybackState() == Player.STATE_IDLE) { if (playbackPreparer != null) { playbackPreparer.preparePlayback(); } } else if (player.getPlaybackState() == Player.STATE_ENDED) { controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET); } if (controlDispatcher.dispatchSetPlayWhenReady(player, true)) { getCallback().onPlayStateChanged(this); } }
private void next() { Timeline timeline = player.getCurrentTimeline(); if (timeline.isEmpty() || player.isPlayingAd()) { return; } int windowIndex = player.getCurrentWindowIndex(); int nextWindowIndex = player.getNextWindowIndex(); if (nextWindowIndex != C.INDEX_UNSET) { seekTo(nextWindowIndex, C.TIME_UNSET); } else if (timeline.getWindow(windowIndex, window).isDynamic) { seekTo(windowIndex, C.TIME_UNSET); } }
@Override public void onSkipToNext(Player player) { Timeline timeline = player.getCurrentTimeline(); if (timeline.isEmpty() || player.isPlayingAd()) { return; } int windowIndex = player.getCurrentWindowIndex(); int nextWindowIndex = player.getNextWindowIndex(); if (nextWindowIndex != C.INDEX_UNSET) { player.seekTo(nextWindowIndex, C.TIME_UNSET); } else if (timeline.getWindow(windowIndex, window).isDynamic) { player.seekTo(windowIndex, C.TIME_UNSET); } }
private void seekToTimeBarPosition(long positionMs) { int windowIndex; Timeline timeline = player.getCurrentTimeline(); if (multiWindowTimeBar && !timeline.isEmpty()) { int windowCount = timeline.getWindowCount(); windowIndex = 0; while (true) { long windowDurationMs = timeline.getWindow(windowIndex, window).getDurationMs(); if (positionMs < windowDurationMs) { break; } else if (windowIndex == windowCount - 1) { // Seeking past the end of the last window should seek to the end of the timeline. positionMs = windowDurationMs; break; } positionMs -= windowDurationMs; windowIndex++; } } else { windowIndex = player.getCurrentWindowIndex(); } seekTo(windowIndex, positionMs); }
private void previous() { Timeline timeline = player.getCurrentTimeline(); if (timeline.isEmpty() || player.isPlayingAd()) { return; } int windowIndex = player.getCurrentWindowIndex(); timeline.getWindow(windowIndex, window); int previousWindowIndex = player.getPreviousWindowIndex(); if (previousWindowIndex != C.INDEX_UNSET && (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS || (window.isDynamic && !window.isSeekable))) { seekTo(previousWindowIndex, C.TIME_UNSET); } else { seekTo(0); } }
@Override public void onSkipToPrevious(Player player) { Timeline timeline = player.getCurrentTimeline(); if (timeline.isEmpty() || player.isPlayingAd()) { return; } int windowIndex = player.getCurrentWindowIndex(); timeline.getWindow(windowIndex, window); int previousWindowIndex = player.getPreviousWindowIndex(); if (previousWindowIndex != C.INDEX_UNSET && (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS || (window.isDynamic && !window.isSeekable))) { player.seekTo(previousWindowIndex, C.TIME_UNSET); } else { player.seekTo(0); } }
private void updateNavigation() { if (!isVisible() || !isAttachedToWindow) { return; } Timeline timeline = player != null ? player.getCurrentTimeline() : null; boolean haveNonEmptyTimeline = timeline != null && !timeline.isEmpty(); boolean isSeekable = false; boolean enablePrevious = false; boolean enableNext = false; if (haveNonEmptyTimeline && !player.isPlayingAd()) { int windowIndex = player.getCurrentWindowIndex(); timeline.getWindow(windowIndex, window); isSeekable = window.isSeekable; enablePrevious = isSeekable || !window.isDynamic || player.hasPrevious(); enableNext = window.isDynamic || player.hasNext(); } setButtonEnabled(enablePrevious, previousButton); setButtonEnabled(enableNext, nextButton); setButtonEnabled(fastForwardMs > 0 && isSeekable, fastForwardButton); setButtonEnabled(rewindMs > 0 && isSeekable, rewindButton); if (timeBar != null) { timeBar.setEnabled(isSeekable); } }
long eventPositionMs; boolean isInCurrentWindow = timeline == player.getCurrentTimeline() && windowIndex == player.getCurrentWindowIndex(); if (mediaPeriodId != null && mediaPeriodId.isAd()) { boolean isCurrentAd =
playbackPositionMs = this.currentPlayer.getCurrentPosition(); playWhenReady = this.currentPlayer.getPlayWhenReady(); windowIndex = this.currentPlayer.getCurrentWindowIndex(); if (windowIndex != currentItemIndex) { playbackPositionMs = C.TIME_UNSET;
controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET);