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

fix: validation for stalled and suspended event in iOS when headphones disconnect #6199

Merged
merged 7 commits into from
Oct 4, 2019
Prev Previous commit
Next Next commit
Establish if we have enough extra buffer in the current time range
  • Loading branch information
marcodeltorob committed Sep 6, 2019
commit 10761f0c75b1f18418bddedf65080e70b4f72527
14 changes: 10 additions & 4 deletions src/js/tech/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,17 @@ class Html5 extends Tech {
const buffered = this.buffered();

if (buffered.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should do

if (!bufferred.length) {
  return;
}

to eliminate the scope here.

const end = buffered.end(buffered.length - 1);
let extraBuffer = false;

// if tech is not paused, browser has internet connection & end + safe delta >= current time
if ((!this.paused() && window.navigator.onLine) &&
(end + SAFE_TIME_DELTA >= this.currentTime())) {
// Establish if we have an extra buffer in the current time range playing.
for (let i = 0; i < buffered.length; i++) {
if (buffered.start(i) <= this.currentTime() <= buffered.end(i) + SAFE_TIME_DELTA) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think what we want is to check if there is anything in the forward buffer. It seems that if the currentTime is equal to the buffered.end, then we don't have anything in the forward buffer. Maybe just buffered.start <= currentTime < buffered.end?
  2. Should we adjust the buffered.start using SAFE_TIME_DELTA as well? Maybe not.
  3. We might as well break out of the loop when we set extraBuffer = true.

extraBuffer = true;
}
}

// if tech is not paused, browser has internet connection & player has extraBuffer inside the timeRange
if ((!this.paused() && window.navigator.onLine) && extraBuffer) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the extra parens are necessary as the expression will just evaluate each item in turn.

Suggested change
if ((!this.paused() && window.navigator.onLine) && extraBuffer) {
if (!this.paused() && window.navigator.onLine && extraBuffer) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should we check extraBuffer first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense and we can decide quicker the state of the playback.

this.pause();
}
}
Expand Down