Skip to content

Commit

Permalink
feat: Add a buffer fullness method (shaka-project#3392)
Browse files Browse the repository at this point in the history
  • Loading branch information
surajkumar-sk authored May 11, 2021
1 parent d47c823 commit 0f00d1c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2838,6 +2838,32 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
return this.config_;
}

/**
* Returns the ratio of video length buffered compared to buffering Goal
* @return {number}
* @export
*/
getBufferFullness() {
if (this.video_) {
const bufferedLength = this.video_.buffered.length;
const bufferedEnd =
bufferedLength ? this.video_.buffered.end(bufferedLength - 1) : 0;
const bufferingGoal = this.getConfiguration().streaming.bufferingGoal;
const lengthToBeBuffered = Math.min(this.video_.currentTime +
bufferingGoal, this.seekRange().end);

if (bufferedEnd >= lengthToBeBuffered) {
return 1;
} else if (bufferedEnd <= this.video_.currentTime) {
return 0;
} else if (bufferedEnd < lengthToBeBuffered) {
return ((bufferedEnd - this.video_.currentTime) /
(lengthToBeBuffered - this.video_.currentTime));
}
}
return 0;
}

/**
* Reset configuration to default.
* @export
Expand Down

0 comments on commit 0f00d1c

Please sign in to comment.