From af8c98c80b2d7eebe7baf7d68d00caadc67e5400 Mon Sep 17 00:00:00 2001 From: Dzianis Dashkevich Date: Tue, 26 Dec 2023 17:52:50 -0500 Subject: [PATCH 1/2] fix: account difference between duration info in the playlist and the actual duration --- src/playlist.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/playlist.js b/src/playlist.js index 82fc01979..96608e761 100644 --- a/src/playlist.js +++ b/src/playlist.js @@ -511,8 +511,16 @@ export const getMediaInfoForTime = function({ time -= partAndSegment.duration; - if (time === 0) { - // we are exactly at the end of the current segment + if (time === 0 || (time + TIME_FUDGE_FACTOR) >= 0) { + // 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 From 72e5c0557f699533d8a627a47e2a905aa03d7f66 Mon Sep 17 00:00:00 2001 From: Dzianis Dashkevich Date: Tue, 26 Dec 2023 18:42:59 -0500 Subject: [PATCH 2/2] fix: account for zero length segments --- src/playlist.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/playlist.js b/src/playlist.js index 96608e761..8346a7af3 100644 --- a/src/playlist.js +++ b/src/playlist.js @@ -511,7 +511,11 @@ export const getMediaInfoForTime = function({ time -= partAndSegment.duration; - if (time === 0 || (time + TIME_FUDGE_FACTOR) >= 0) { + 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