diff --git a/lib/player/player.js b/lib/player/player.js index 3ff08769d..b794e7765 100644 --- a/lib/player/player.js +++ b/lib/player/player.js @@ -844,18 +844,21 @@ shaka.player.Player.prototype.onWatchdogTimer_ = function() { // buffering. |buffered| will show the intersection of buffered ranges for // both audio and video, so this is an accurate way to sense that we are // buffering. The 'stalled', 'waiting', and 'suspended' events do not work - // for this purpose as of Chrome 38. + // for this purpose as of Chrome 38. Nor will video.readyState. var bufferEnd = buffered.length ? buffered.end(buffered.length - 1) : 0; - var underflow = this.video_.currentTime - bufferEnd; + var buffered = bufferEnd - this.video_.currentTime; + var threshold = shaka.player.Player.UNDERFLOW_THRESHOLD_; + var fudgedBufferEnd = bufferEnd + shaka.player.Player.BUFFERED_FUDGE_FACTOR_; if (!this.buffering_) { - if (underflow > shaka.player.Player.UNDERFLOW_THRESHOLD_) { + // Don't go into a buffering state at the end of the video. + if (fudgedBufferEnd < this.video_.duration && buffered < threshold) { this.enterBufferingState_(); } } else { var resumeThreshold = this.videoSource_.getResumeThreshold(); shaka.asserts.assert(resumeThreshold > 0); - if (underflow < -resumeThreshold) { + if (buffered > resumeThreshold) { this.endBufferingState_(); this.video_.play(); } @@ -864,13 +867,23 @@ shaka.player.Player.prototype.onWatchdogTimer_ = function() { /** - * The threshold for underflow, in seconds. If the play head is outside the - * buffered range by this much, we will consider the player to be out of data. + * The threshold for underflow, in seconds. If there is less than this amount + * of data buffered, we will consider the player to be out of data. * * @private {number} * @const */ -shaka.player.Player.UNDERFLOW_THRESHOLD_ = 0.050; +shaka.player.Player.UNDERFLOW_THRESHOLD_ = 0.1; + + +/** + * A fudge factor applied to buffered ranges to determine if the end of the + * video is buffered. + * + * @private {number} + * @const + */ +shaka.player.Player.BUFFERED_FUDGE_FACTOR_ = 0.05; /**