/** * Returns the duration of the window in milliseconds, or {@link C#TIME_UNSET} if unknown. */ public long getDurationMs() { return C.usToMs(durationUs); }
/** * Returns the default position relative to the start of the window at which to begin playback, * in milliseconds. May be {@link C#TIME_UNSET} if and only if the window was populated with a * non-zero default position projection, and if the specified projection cannot be performed * whilst remaining within the bounds of the window. */ public long getDefaultPositionMs() { return C.usToMs(defaultPositionUs); }
/** * Returns the position of the start of this window relative to the start of the first period * belonging to it, in milliseconds. */ public long getPositionInFirstPeriodMs() { return C.usToMs(positionInFirstPeriodUs); }
/** * Returns the duration of the period in milliseconds, or {@link C#TIME_UNSET} if unknown. */ public long getDurationMs() { return C.usToMs(durationUs); }
/** * Returns the position of the start of this period relative to the start of the window to which * it belongs, in milliseconds. May be negative if the start of the period is not within the * window. */ public long getPositionInWindowMs() { return C.usToMs(positionInWindowUs); }
private long adjustMediaTime(long mediaTimeUs) { long mediaTimeMs = C.usToMs(mediaTimeUs); return mediaTimeMs == C.TIME_UNSET ? C.TIME_UNSET : mediaTimeOffsetMs + mediaTimeMs; }
@Override protected long getMediaTimeForChildMediaTime(Void id, long mediaTimeMs) { if (mediaTimeMs == C.TIME_UNSET) { return C.TIME_UNSET; } long startMs = C.usToMs(startUs); long clippedTimeMs = Math.max(0, mediaTimeMs - startMs); if (endUs != C.TIME_END_OF_SOURCE) { clippedTimeMs = Math.min(C.usToMs(endUs) - startMs, clippedTimeMs); } return clippedTimeMs; }
@Override public long getTotalBufferedDuration() { return Math.max(0, C.usToMs(playbackInfo.totalBufferedDurationUs)); }
public boolean isSnapshotValid() { if (playlistSnapshot == null) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); long snapshotValidityDurationMs = Math.max(30000, C.usToMs(playlistSnapshot.durationUs)); return playlistSnapshot.hasEndTag || playlistSnapshot.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_EVENT || playlistSnapshot.playlistType == HlsMediaPlaylist.PLAYLIST_TYPE_VOD || lastSnapshotLoadMs + snapshotValidityDurationMs > currentTimeMs; }
/** * Advances {@link #firstSampleToOutputIndex} to point to the sync sample before the specified * seek time in the current fragment. * * @param timeUs The seek time, in microseconds. */ public void seek(long timeUs) { long timeMs = C.usToMs(timeUs); int searchIndex = currentSampleIndex; while (searchIndex < fragment.sampleCount && fragment.getSamplePresentationTime(searchIndex) < timeMs) { if (fragment.sampleIsSyncFrameTable[searchIndex]) { firstSampleToOutputIndex = searchIndex; } searchIndex++; } }
@Override public Window getWindow( int windowIndex, Window window, boolean setTag, long defaultPositionProjectionUs) { timeline.getWindow( /* windowIndex= */ 0, window, setTag, /* defaultPositionProjectionUs= */ 0); window.positionInFirstPeriodUs += startUs; window.durationUs = durationUs; window.isDynamic = isDynamic; if (window.defaultPositionUs != C.TIME_UNSET) { window.defaultPositionUs = Math.max(window.defaultPositionUs, startUs); window.defaultPositionUs = endUs == C.TIME_UNSET ? window.defaultPositionUs : Math.min(window.defaultPositionUs, endUs); window.defaultPositionUs -= startUs; } long startMs = C.usToMs(startUs); if (window.presentationStartTimeMs != C.TIME_UNSET) { window.presentationStartTimeMs += startMs; } if (window.windowStartTimeMs != C.TIME_UNSET) { window.windowStartTimeMs += startMs; } return window; }
private long periodPositionUsToWindowPositionMs(MediaPeriodId periodId, long positionUs) { long positionMs = C.usToMs(positionUs); playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period); positionMs += period.getPositionInWindowMs(); return positionMs; }
@Override public long getCurrentPosition() { if (shouldMaskPosition()) { return maskingWindowPositionMs; } else if (playbackInfo.periodId.isAd()) { return C.usToMs(playbackInfo.positionUs); } else { return periodPositionUsToWindowPositionMs(playbackInfo.periodId, playbackInfo.positionUs); } }
@Override public long getBufferedPosition() { if (isPlayingAd()) { return playbackInfo.loadingMediaPeriodId.equals(playbackInfo.periodId) ? C.usToMs(playbackInfo.bufferedPositionUs) : getDuration(); } return getContentBufferedPosition(); }
@Override public long getContentPosition() { if (isPlayingAd()) { playbackInfo.timeline.getPeriodByUid(playbackInfo.periodId.periodUid, period); return period.getPositionInWindowMs() + C.usToMs(playbackInfo.contentPositionUs); } else { return getCurrentPosition(); } }
@Override public long getDuration() { if (isPlayingAd()) { MediaPeriodId periodId = playbackInfo.periodId; playbackInfo.timeline.getPeriodByUid(periodId.periodUid, period); long adDurationUs = period.getAdDurationUs(periodId.adGroupIndex, periodId.adIndexInAdGroup); return C.usToMs(adDurationUs); } return getContentDuration(); }
@Override public void onTimelineChanged( Timeline timeline, @Nullable Object manifest, @Player.TimelineChangeReason int reason) { if (reason == Player.TIMELINE_CHANGE_REASON_RESET) { // The player is being reset and this source will be released. return; } Assertions.checkArgument(timeline.getPeriodCount() == 1); this.timeline = timeline; long contentDurationUs = timeline.getPeriod(0, period).durationUs; contentDurationMs = C.usToMs(contentDurationUs); if (contentDurationUs != C.TIME_UNSET) { adPlaybackState = adPlaybackState.withContentDurationUs(contentDurationUs); } updateImaStateForPlayerState(); }
@Override protected FakeMediaPeriod createFakeMediaPeriod( MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, EventDispatcher eventDispatcher, @Nullable TransferListener transferListener) { eventDispatcher.downstreamFormatChanged( new MediaLoadData( C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, /* trackFormat= */ null, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */ null, C.usToMs(eventStartUs), C.usToMs(eventEndUs))); return super.createFakeMediaPeriod( id, trackGroupArray, allocator, eventDispatcher, transferListener); } };
@Override public SeekPoints getSeekPoints(long timeUs) { timeUs = Util.constrainValue(timeUs, 0, durationUs); Pair<Long, Long> timeMsAndPosition = linearlyInterpolate(C.usToMs(timeUs), referenceTimesMs, referencePositions); timeUs = C.msToUs(timeMsAndPosition.first); long position = timeMsAndPosition.second; return new SeekPoints(new SeekPoint(timeUs, position)); }
@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(); } }