From 65a16ed145fd80785846f5e2b3e3b37af4a15487 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Thu, 11 Apr 2019 15:15:42 -0700 Subject: [PATCH] Fix buffer detection in native HLS 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 --- lib/media/play_rate_controller.js | 2 ++ lib/player.js | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/media/play_rate_controller.js b/lib/media/play_rate_controller.js index eaf9d4df8a..037bcc056c 100644 --- a/lib/media/play_rate_controller.js +++ b/lib/media/play_rate_controller.js @@ -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 */ diff --git a/lib/player.js b/lib/player.js index 66caf18107..a73bd25965 100644 --- a/lib/player.js +++ b/lib/player.js @@ -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; @@ -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; };