From ad2eef6952b6164a67a5ab1d85f3a0e7071eb7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Mon, 12 Jun 2023 12:44:24 +0200 Subject: [PATCH] fix(HLS): Fix live playlist update when using no LL in a LL stream (#5282) This happens because the last segment in an LL stream may not be complete and may not have EXTINF --- lib/hls/hls_parser.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index fa1818a2ab..84cffd7a5c 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -2647,14 +2647,19 @@ shaka.hls.HlsParser = class { let lastTargetDuration = Infinity; const segments = playlist.segments; if (segments.length) { - const lastSegment = segments[segments.length - 1]; - const extinfTag = - shaka.hls.Utils.getFirstTagWithName(lastSegment.tags, 'EXTINF'); - if (extinfTag) { - // The EXTINF tag format is '#EXTINF:,[]'. - // We're interested in the duration part. - const extinfValues = extinfTag.value.split(','); - lastTargetDuration = Number(extinfValues[0]); + let segmentIndex = segments.length - 1; + while (segmentIndex >= 0) { + const segment = segments[segmentIndex]; + const extinfTag = + shaka.hls.Utils.getFirstTagWithName(segment.tags, 'EXTINF'); + if (extinfTag) { + // The EXTINF tag format is '#EXTINF:<duration>,[<title>]'. + // We're interested in the duration part. + const extinfValues = extinfTag.value.split(','); + lastTargetDuration = Number(extinfValues[0]); + break; + } + segmentIndex--; } } this.lastTargetDuration_ = Math.min(