Search in sources :

Example 6 with Timeline

use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.

the class HlsMediaSource method onPrimaryPlaylistRefreshed.

@Override
public void onPrimaryPlaylistRefreshed(HlsMediaPlaylist playlist) {
    SinglePeriodTimeline timeline;
    long windowDefaultStartPositionUs = playlist.startOffsetUs;
    if (playlistTracker.isLive()) {
        long periodDurationUs = playlist.hasEndTag ? (playlist.startTimeUs + playlist.durationUs) : C.TIME_UNSET;
        List<HlsMediaPlaylist.Segment> segments = playlist.segments;
        if (windowDefaultStartPositionUs == C.TIME_UNSET) {
            windowDefaultStartPositionUs = segments.isEmpty() ? 0 : segments.get(Math.max(0, segments.size() - 3)).relativeStartTimeUs;
        }
        timeline = new SinglePeriodTimeline(periodDurationUs, playlist.durationUs, playlist.startTimeUs, windowDefaultStartPositionUs, true, !playlist.hasEndTag);
    } else /* not live */
    {
        if (windowDefaultStartPositionUs == C.TIME_UNSET) {
            windowDefaultStartPositionUs = 0;
        }
        timeline = new SinglePeriodTimeline(playlist.startTimeUs + playlist.durationUs, playlist.durationUs, playlist.startTimeUs, windowDefaultStartPositionUs, true, false);
    }
    sourceListener.onSourceInfoRefreshed(timeline, new HlsManifest(playlistTracker.getMasterPlaylist(), playlist));
}
Also used : SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline)

Example 7 with Timeline

use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.

the class SsMediaSource method processManifest.

// Internal methods
private void processManifest() {
    for (int i = 0; i < mediaPeriods.size(); i++) {
        mediaPeriods.get(i).updateManifest(manifest);
    }
    Timeline timeline;
    if (manifest.isLive) {
        long startTimeUs = Long.MAX_VALUE;
        long endTimeUs = Long.MIN_VALUE;
        for (int i = 0; i < manifest.streamElements.length; i++) {
            StreamElement element = manifest.streamElements[i];
            if (element.chunkCount > 0) {
                startTimeUs = Math.min(startTimeUs, element.getStartTimeUs(0));
                endTimeUs = Math.max(endTimeUs, element.getStartTimeUs(element.chunkCount - 1) + element.getChunkDurationUs(element.chunkCount - 1));
            }
        }
        if (startTimeUs == Long.MAX_VALUE) {
            timeline = new SinglePeriodTimeline(C.TIME_UNSET, false);
        } else {
            if (manifest.dvrWindowLengthUs != C.TIME_UNSET && manifest.dvrWindowLengthUs > 0) {
                startTimeUs = Math.max(startTimeUs, endTimeUs - manifest.dvrWindowLengthUs);
            }
            long durationUs = endTimeUs - startTimeUs;
            long defaultStartPositionUs = durationUs - C.msToUs(livePresentationDelayMs);
            if (defaultStartPositionUs < MIN_LIVE_DEFAULT_START_POSITION_US) {
                // The default start position is too close to the start of the live window. Set it to the
                // minimum default start position provided the window is at least twice as big. Else set
                // it to the middle of the window.
                defaultStartPositionUs = Math.min(MIN_LIVE_DEFAULT_START_POSITION_US, durationUs / 2);
            }
            timeline = new SinglePeriodTimeline(C.TIME_UNSET, durationUs, startTimeUs, defaultStartPositionUs, true, /* isSeekable */
            true);
        }
    } else {
        boolean isSeekable = manifest.durationUs != C.TIME_UNSET;
        timeline = new SinglePeriodTimeline(manifest.durationUs, isSeekable);
    }
    sourceListener.onSourceInfoRefreshed(timeline, manifest);
}
Also used : SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) Timeline(com.google.android.exoplayer2.Timeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) StreamElement(com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement)

Example 8 with Timeline

use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.

the class PlaybackControlView method updateNavigation.

private void updateNavigation() {
    if (!isVisible() || !isAttachedToWindow) {
        return;
    }
    Timeline currentTimeline = player != null ? player.getCurrentTimeline() : null;
    boolean haveNonEmptyTimeline = currentTimeline != null && !currentTimeline.isEmpty();
    boolean isSeekable = false;
    boolean enablePrevious = false;
    boolean enableNext = false;
    if (haveNonEmptyTimeline) {
        int currentWindowIndex = player.getCurrentWindowIndex();
        currentTimeline.getWindow(currentWindowIndex, currentWindow);
        isSeekable = currentWindow.isSeekable;
        enablePrevious = currentWindowIndex > 0 || isSeekable || !currentWindow.isDynamic;
        enableNext = (currentWindowIndex < currentTimeline.getWindowCount() - 1) || currentWindow.isDynamic;
    }
    setButtonEnabled(enablePrevious, previousButton);
    setButtonEnabled(enableNext, nextButton);
    setButtonEnabled(fastForwardMs > 0 && isSeekable, fastForwardButton);
    setButtonEnabled(rewindMs > 0 && isSeekable, rewindButton);
    if (progressBar != null) {
        progressBar.setEnabled(isSeekable);
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Example 9 with Timeline

use of com.google.android.exoplayer2.Timeline in project ExoPlayer by google.

the class PlaybackControlView method previous.

private void previous() {
    Timeline currentTimeline = player.getCurrentTimeline();
    if (currentTimeline.isEmpty()) {
        return;
    }
    int currentWindowIndex = player.getCurrentWindowIndex();
    currentTimeline.getWindow(currentWindowIndex, currentWindow);
    if (currentWindowIndex > 0 && (player.getCurrentPosition() <= MAX_POSITION_FOR_SEEK_TO_PREVIOUS || (currentWindow.isDynamic && !currentWindow.isSeekable))) {
        seekTo(currentWindowIndex - 1, C.TIME_UNSET);
    } else {
        seekTo(0);
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Example 10 with Timeline

use of com.google.android.exoplayer2.Timeline in project LeafPic by HoraApps.

the class CustomPlayBackController method next.

private void next() {
    Timeline currentTimeline = player.getCurrentTimeline();
    if (currentTimeline == null) {
        return;
    }
    int currentWindowIndex = player.getCurrentWindowIndex();
    if (currentWindowIndex < currentTimeline.getWindowCount() - 1) {
        player.seekToDefaultPosition(currentWindowIndex + 1);
    } else if (currentTimeline.getWindow(currentWindowIndex, window, false).isDynamic) {
        player.seekToDefaultPosition();
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Aggregations

Timeline (com.google.android.exoplayer2.Timeline)15 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)2 Listener (com.google.android.exoplayer2.source.MediaSource.Listener)1 SampleStream (com.google.android.exoplayer2.source.SampleStream)1 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1 StreamElement (com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement)1 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)1 TrackSelectorResult (com.google.android.exoplayer2.trackselection.TrackSelectorResult)1