Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a method to get the ratio of video length buffered compared to bufferingGoal #3392

Merged
merged 11 commits into from
May 11, 2021
26 changes: 26 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2837,6 +2837,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_) {
surajkumar-sk marked this conversation as resolved.
Show resolved Hide resolved
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