Skip to content

Commit

Permalink
Fix buffer detection in native HLS
Browse files Browse the repository at this point in the history
Use a fudge factor to fix infinite buffering at the end of a native
HLS playback.  This could go away once we stop managing buffering
state above the browser using playbackRate=0.

Issue #997

Change-Id: Ib4a6fd5aa10dd84f9cfa4972d57db2cc63d7668d
  • Loading branch information
joeyparrish committed Apr 16, 2019
1 parent 133f161 commit 65a16ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/media/play_rate_controller.js
Expand Up @@ -26,6 +26,8 @@ goog.require('shaka.util.Timer');
* the playback rate on the media element can change outside of the controller,
* the playback controller will need to be updated to stay in-sync.
*
* TODO: Try not to manage buffering above the browser with playbackRate=0.
*
* @implements {shaka.util.IReleasable}
* @final
*/
Expand Down
10 changes: 9 additions & 1 deletion lib/player.js
Expand Up @@ -128,6 +128,7 @@ shaka.Player = function(mediaElement, dependencyInjector) {
// been loaded and are not re-used between loads.
/** @private {shaka.util.Timer} */
this.bufferPoller_ = null;

/** @private {shaka.media.BufferingObserver} */
this.bufferObserver_ = null;

Expand Down Expand Up @@ -4831,7 +4832,14 @@ shaka.Player.prototype.isBufferedToEndSrc_ = function() {
// If we have buffered to the duration of the content, it means we will have
// enough content to buffer to the end of the presentation.
const bufferEnd = shaka.media.TimeRangesUtils.bufferEnd(this.video_.buffered);
return bufferEnd >= this.video_.duration;

// Because Safari's native HLS reports slightly inaccurate values for
// bufferEnd here, we use a fudge factor. Without this, we can end up in a
// buffering state at the end of the stream.
// TODO: Try to remove the fudge here once we no longer manage buffering state
// above the browser with playbackRate=0.
const fudge = 0.05; // 50 ms
return bufferEnd >= this.video_.duration - fudge;
};


Expand Down

0 comments on commit 65a16ed

Please sign in to comment.