From 455b020e02d9debf0980bd208d67b3a898413d53 Mon Sep 17 00:00:00 2001 From: Dzianis Dashkevich <98566601+dzianis-dashkevich@users.noreply.github.com> Date: Tue, 26 Dec 2023 19:39:55 -0500 Subject: [PATCH] fix: Account for difference between duration info in the playlist and the actual duration (#1470) * fix: account difference between duration info in the playlist and the actual duration * fix: account for zero length segments --------- Co-authored-by: Dzianis Dashkevich --- src/playlist.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/playlist.js b/src/playlist.js index 82fc01979..8346a7af3 100644 --- a/src/playlist.js +++ b/src/playlist.js @@ -511,8 +511,20 @@ export const getMediaInfoForTime = function({ time -= partAndSegment.duration; - if (time === 0) { - // we are exactly at the end of the current segment + const canUseFudgeFactor = partAndSegment.duration > TIME_FUDGE_FACTOR; + const isExactlyAtTheEnd = time === 0; + const isExtremelyCloseToTheEnd = canUseFudgeFactor && (time + TIME_FUDGE_FACTOR >= 0); + + if (isExactlyAtTheEnd || isExtremelyCloseToTheEnd) { + // 1) We are exactly at the end of the current segment. + // 2) We are extremely close to the end of the current segment (The difference is less than 1 / 30). + // We may encounter this situation when + // we don't have exact match between segment duration info in the manifest and the actual duration of the segment + // For example: + // We appended 3 segments 10 seconds each, meaning we should have 30 sec buffered, + // but we the actual buffered is 29.99999 + // + // In both cases: // if we passed current time -> it means that we already played current segment // if we passed buffered.end -> it means that this segment is already loaded and buffered