From d412dc97dcf7b7e4789fb30520a439394bc15dd5 Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Mon, 30 Apr 2018 12:50:08 -0700 Subject: [PATCH] Fix seeking in live HLS streams Issue:#4187 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=194829857 --- RELEASENOTES.md | 2 ++ .../google/android/exoplayer2/source/hls/HlsChunkSource.java | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 47180ebfc8..60bf20eb7a 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -81,6 +81,8 @@ ([#4016](https://github.com/google/ExoPlayer/issues/4016)). * Add support for multiple #EXT-X-MAP tags in a media playlist ([#4164](https://github.com/google/ExoPlayer/issues/4182)). + * Fix seeking in live streams + ([#4187](https://github.com/google/ExoPlayer/issues/4187)). * Fix ClearKey decryption error if the key contains a forward slash ([#4075](https://github.com/google/ExoPlayer/issues/4075)). * Fix crash when switching surface on Huawei P9 Lite diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java index 7271b3b09c..9a02bd785a 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java @@ -261,10 +261,12 @@ import java.util.List; // If the playlist is too old to contain the chunk, we need to refresh it. chunkMediaSequence = mediaPlaylist.mediaSequence + mediaPlaylist.segments.size(); } else { + // The playlist start time is subtracted from the target position because the segment start + // times are relative to the start of the playlist, but the target position is not. chunkMediaSequence = Util.binarySearchFloor( mediaPlaylist.segments, - targetPositionUs, + /* value= */ targetPositionUs - mediaPlaylist.startTimeUs, /* inclusive= */ true, /* stayInBounds= */ !playlistTracker.isLive() || previous == null) + mediaPlaylist.mediaSequence;