Skip to content

Commit

Permalink
Fix Buffering Failure with src=
Browse files Browse the repository at this point in the history
Because of the lack of tests (tests are coming) we did not see that the
buffering system was failing to find media source to check if it had
buffered to the end of the presentation.

This change adds the logic needed to know if it has buffered to the end
for each type of loaded content.

Issue #816
Issue #997

Change-Id: Ief9d4bdc94f3121f889a0efa24a8b3d78377bb9f
  • Loading branch information
vaage committed Apr 10, 2019
1 parent 0147a78 commit ed2c5c3
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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|.
Expand Down

0 comments on commit ed2c5c3

Please sign in to comment.