From 530dd3f733a13190a8f75fd133bcb4aa24b06aaf Mon Sep 17 00:00:00 2001 From: Steve Mayhew Date: Fri, 5 Nov 2021 13:08:20 -0700 Subject: [PATCH] Correct comment on track selection during seek The comment "all should be same" is not correct, it is extremely likely they will be the same but not assured. In either case the seek position will work, it just may not land exactly on a sync point in every variant. --- .../android/exoplayer2/source/hls/HlsChunkSource.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 ee8fe4c2d0f..64f700e0355 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 @@ -257,8 +257,13 @@ public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParame mediaPlaylist = playlistTracker.getPlaylistSnapshot(playlistUrls[selectedIndex], /* isForPlayback= */ true); } - // Resolve to a segment boundary, current track is fine (all should be same). - // and, segments must start with sync (EXT-X-INDEPENDENT-SEGMENTS must be present) + // If segments must start with sync (EXT-X-INDEPENDENT-SEGMENTS is set) and the playlist is not empty + // resolve using the nearest segment start and the next segment (if any) start as the first and second + // sync points. + // Note, the position returned is normalized to the period, so it will work if a track selection changes + // variants before the seek is executed. It is possible it may not land exactly on a segment sync point in the rare + // case the segment boundaries do not align across variants. + // if (mediaPlaylist != null && mediaPlaylist.hasIndependentSegments && !mediaPlaylist.segments.isEmpty()) { long startOfPlaylistInPeriodUs = mediaPlaylist.startTimeUs - playlistTracker.getInitialStartTimeUs(); long targetPositionInPlaylistUs = positionUs - startOfPlaylistInPeriodUs;