From a049382cd743b35f665af251ca493e21f864a771 Mon Sep 17 00:00:00 2001 From: olly Date: Mon, 18 Jan 2016 05:37:52 -0800 Subject: [PATCH] Treat seeks in HLS live to be at t=0, as in ExtractorSampleSource. This makes sense until we need to support seeking in the live window. Issue: #676 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=112402026 --- .../google/android/exoplayer/hls/HlsChunkSource.java | 11 +++++++++++ .../google/android/exoplayer/hls/HlsSampleSource.java | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java index 347765f3c7..803f8fbd79 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java @@ -260,6 +260,17 @@ public class HlsChunkSource implements HlsTrackSelector.Output { return fatalError == null; } + /** + * Returns whether this is a live playback. + *

+ * This method should only be called after the source has been prepared. + * + * @return True if this is a live playback. False otherwise. + */ + public boolean isLive() { + return live; + } + /** * Returns the duration of the source, or {@link C#UNKNOWN_TIME_US} if the duration is unknown. *

diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java index cecbaa55a0..32a46c9223 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java @@ -206,6 +206,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader, loadControl.register(this, bufferSizeContribution); loadControlRegistered = true; } + // Treat enabling of a live stream as occurring at t=0 in both of the blocks below. + positionUs = chunkSource.isLive() ? 0 : positionUs; int chunkSourceTrack = chunkSourceTrackIndices[track]; if (chunkSourceTrack != -1 && chunkSourceTrack != chunkSource.getSelectedTrackIndex()) { // This is a primary track whose corresponding chunk source track is different to the one @@ -359,6 +361,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader, public void seekToUs(long positionUs) { Assertions.checkState(prepared); Assertions.checkState(enabledTrackCount > 0); + // Treat all seeks into live streams as being to t=0. + positionUs = chunkSource.isLive() ? 0 : positionUs; // Ignore seeks to the current position. long currentPositionUs = isPendingReset() ? pendingResetPositionUs : downstreamPositionUs;