@Override public void onTimelineChanged(Timeline timeline, Object manifest, int reason) { int periodCount = timeline.getPeriodCount(); int windowCount = timeline.getWindowCount(); Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount); for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getPeriod(i, period); Log.d(TAG, " " + "period [" + getTimeString(period.getDurationMs()) + "]"); } if (periodCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getWindow(i, window); Log.d(TAG, " " + "window [" + getTimeString(window.getDurationMs()) + ", " + window.isSeekable + ", " + window.isDynamic + "]"); } if (windowCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } Log.d(TAG, "]"); }
" " + "window [" + getTimeString(window.getDurationMs()) + ", " + window.isSeekable
Builder.AUDIO_FORMAT)); long periodDurationMs = SINGLE_PERIOD_TIMELINE.getWindow(/* windowIndex= */ 0, new Window()).getDurationMs(); ActionSchedule actionSchedule = new ActionSchedule.Builder("AnalyticsCollectorTest")
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); }
timeline.getWindow(index, window); long windowDurationMs = window.getDurationMs(); if (cumulativePositionMs < positionMs && positionMs <= (cumulativePositionMs + windowDurationMs)) { player.seekTo(index, positionMs - cumulativePositionMs);
/** * TODO: Expose this * Returns the position in the media. If <code>limitToCurrentWindow</code> is <code>true</code> then the position * in the current window will be returned, otherwise the total position across all windows will be returned. * These should only be different if the media in playback has multiple windows (e.g. in the case of using a * <code>ConcatenatingMediaSource</code> with more than 1 source) * * @param limitToCurrentWindow If <code>true</code> the position within the current window will be returned * @return The current position in the media */ public long getCurrentPosition(boolean limitToCurrentWindow) { long positionInCurrentWindow = player.getCurrentPosition(); if (limitToCurrentWindow) { return positionInCurrentWindow; } // TODO cache the total time at the start of each window (e.g. Map<WindowIndex, cumulativeStartTimeMs>) // Adds the preceding window durations Timeline timeline = player.getCurrentTimeline(); int maxWindowIndex = Math.min(timeline.getWindowCount() - 1, player.getCurrentWindowIndex()); long cumulativePositionMs = 0; Timeline.Window window = new Timeline.Window(); for (int index = 0; index < maxWindowIndex; index++) { timeline.getWindow(index, window); cumulativePositionMs += window.getDurationMs(); } return cumulativePositionMs + positionInCurrentWindow; }
@Override public void onTimelineChanged(Timeline timeline, Object manifest) { int periodCount = timeline.getPeriodCount(); int windowCount = timeline.getWindowCount(); Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount); for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getPeriod(i, period); Log.d(TAG, " " + "period [" + getTimeString(period.getDurationMs()) + "]"); } if (periodCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getWindow(i, window); Log.d(TAG, " " + "window [" + getTimeString(window.getDurationMs()) + ", " + window.isSeekable + ", " + window.isDynamic + "]"); } if (windowCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } Log.d(TAG, "]"); }
new ConcatenatingMediaSource(childMediaSource, childMediaSource); long periodDurationMs = SINGLE_PERIOD_TIMELINE.getWindow(/* windowIndex= */ 0, new Window()).getDurationMs(); ActionSchedule actionSchedule = new ActionSchedule.Builder("AnalyticsCollectorTest")
PositionGrabbingMessageTarget targetStartMiddlePeriod = new PositionGrabbingMessageTarget(); PositionGrabbingMessageTarget targetEndLastPeriod = new PositionGrabbingMessageTarget(); long duration1Ms = timeline.getWindow(0, new Window()).getDurationMs(); long duration2Ms = timeline.getWindow(1, new Window()).getDurationMs(); ActionSchedule actionSchedule = new ActionSchedule.Builder("testSendMessages")
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); }
@Override public long getContentBufferedPosition() { if (shouldMaskPosition()) { return maskingWindowPositionMs; } if (playbackInfo.loadingMediaPeriodId.windowSequenceNumber != playbackInfo.periodId.windowSequenceNumber) { return playbackInfo.timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); } long contentBufferedPositionUs = playbackInfo.bufferedPositionUs; if (playbackInfo.loadingMediaPeriodId.isAd()) { Timeline.Period loadingPeriod = playbackInfo.timeline.getPeriodByUid(playbackInfo.loadingMediaPeriodId.periodUid, period); contentBufferedPositionUs = loadingPeriod.getAdGroupTimeUs(playbackInfo.loadingMediaPeriodId.adGroupIndex); if (contentBufferedPositionUs == C.TIME_END_OF_SOURCE) { contentBufferedPositionUs = loadingPeriod.durationUs; } } return periodPositionUsToWindowPositionMs( playbackInfo.loadingMediaPeriodId, contentBufferedPositionUs); }
@Override public long getDuration() { if (timeline.isEmpty()) { return C.INDEX_UNSET; } if (isPlayingAd()) { long adDurationUs = timeline.getPeriod(0, period).getAdDurationUs(adGroupIndex, adIndexInAdGroup); return C.usToMs(adDurationUs); } else { return timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); } }
@Override public final long getContentDuration() { Timeline timeline = getCurrentTimeline(); return timeline.isEmpty() ? C.TIME_UNSET : timeline.getWindow(getCurrentWindowIndex(), window).getDurationMs(); }