Skip to content

Commit

Permalink
fix(FEC-11586): [Player, Safari] The 'FF' (Fast forward) seek button …
Browse files Browse the repository at this point in the history
…is flashing time to time in player due to getting different values from 'isOnLiveEdge' parameter (#611)

Description of the Changes
issue: The live indicator depends on the isOnLiveEdge flag and the isOnLiveEdge flag is calculated by the following formula: liveDuration - currentTime <= segmentDuration × 2.

and the segmentDuration is calculated by the gap between last updated Video.seekable, and Video.bufferd. (and on the assumption that the bufferd is bigger than seekable at any point)

but in practice bufferd Unlike Video.currentTime (which is always progresses), is sometimes reverses which brings the segmentDuration to become a negative number, and hence although that current time is close enough to seekable to be considered on live, the condition returns false since the liveDuration - currentTime would always be a positive number

fix: The solution is to not rely on the bufferd to determine the liveDuration but on the gap between the seekables themself.

solves FEC-11586
  • Loading branch information
JonathanTGold authored Oct 31, 2021
1 parent 3c1d5ae commit 2d87557
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/engines/html5/media-source/adapters/native-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
}

get liveDuration() {
return this._getLiveEdge() + this.getSegmentDuration();
return this._getLiveEdge();
}

/**
Expand Down Expand Up @@ -1157,16 +1157,33 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
*/
_handleLiveDurationChange(): void {
this._liveDurationChangeInterval = setInterval(() => {
this._calculateSegmentDuration();
const liveEdge = this._getLiveEdge();
if (this._liveEdge !== liveEdge) {
this._liveEdge = liveEdge;
this._videoElement.dispatchEvent(new window.Event(Html5EventType.DURATION_CHANGE));
}
}, LIVE_DURATION_INTERVAL_MS);
}

/**
* Calculate the segment duration
* @function _calculateSegmentDuration
* @returns {void}
* @private
*/
_calculateSegmentDuration() {
if (this._videoElement.seekable.start(0) === 0) {
const {buffered, seekable} = this._videoElement;
if (buffered.length && seekable.length) {
this._segmentDuration = (buffered.end(buffered.length - 1) - seekable.end(seekable.length - 1)) / SAFARI_BUFFERED_SEGMENTS_COUNT;
}
}, LIVE_DURATION_INTERVAL_MS);
} else {
const liveEdge = this._getLiveEdge();
if (this._liveEdge !== liveEdge) {
this._segmentDuration = liveEdge - this._liveEdge;
}
}
}

/**
Expand Down

0 comments on commit 2d87557

Please sign in to comment.