diff --git a/lib/player.js b/lib/player.js index 3f1f308fef..feae32f239 100644 --- a/lib/player.js +++ b/lib/player.js @@ -1950,12 +1950,24 @@ shaka.Player.prototype.pollBufferState_ = function() { this.bufferObserver_, 'Need a buffering observer to update'); - const toEnd = this.isBufferedToEnd_(); - const lead = shaka.media.TimeRangesUtils.bufferedAheadOf( + let bufferedToEnd; + switch (this.loadMode_) { + case shaka.Player.LoadMode.SRC_EQUALS: + bufferedToEnd = this.isBufferedToEndSrc_(); + break; + case shaka.Player.LoadMode.MEDIA_SOURCE: + bufferedToEnd = this.isBufferedToEndMS_(); + break; + default: + bufferedToEnd = false; + break; + } + + const bufferLead = shaka.media.TimeRangesUtils.bufferedAheadOf( this.video_.buffered, this.video_.currentTime); - const stateChanged = this.bufferObserver_.update(lead, toEnd); + const stateChanged = this.bufferObserver_.update(bufferLead, bufferedToEnd); // If the state changed, we need to surface the event. if (stateChanged) { @@ -4543,14 +4555,13 @@ shaka.Player.prototype.getPresentationText_ = function() { /** - * Check if the player has buffered content to the end of the presentation. - * Ideally this should only be called when content is loaded, but will assume - * that if nothing can be buffered, it means it is not buffered to the end. + * Assuming the player is playing content with media source, check if the player + * has buffered enough content to make it to the end of the presentation. * * @return {boolean} * @private */ -shaka.Player.prototype.isBufferedToEnd_ = function() { +shaka.Player.prototype.isBufferedToEndMS_ = function() { goog.asserts.assert( this.video_, 'We need a video element to get buffering information'); @@ -4590,6 +4601,31 @@ shaka.Player.prototype.isBufferedToEnd_ = function() { }; +/** + * Assuming the player is playing content with src=, check if the player has + * buffered enough content to make it to the end of the presentation. + * + * @return {boolean} + * @private + */ +shaka.Player.prototype.isBufferedToEndSrc_ = function() { + goog.asserts.assert( + this.video_, + 'We need a video element to get buffering information'); + + // This is a strong guarantee that we are buffered to the end, because it + // means the playhead is already at that end. + if (this.video_.ended) { + return true; + } + + // 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; +}; + + /** * Find the period in |this.manifest_| that contains |variant|. If no period * contains |variant| this will return |null|.