Skip to content

Commit

Permalink
fix: Account for difference between duration info in the playlist and…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
dzianis-dashkevich and Dzianis Dashkevich authored Dec 27, 2023
1 parent f12c197 commit 455b020
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 455b020

Please sign in to comment.