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;