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: Fix selectVariantsByLabel using src= #5154

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4308,6 +4308,19 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
firstVariantWithLabel.language, '', 0, label);

this.chooseVariantAndSwitch_(clearBuffer, safeMargin);
} else if (this.video_ && this.video_.audioTracks) {
const audioTracks = Array.from(this.video_.audioTracks);

let trackMatch = null;

for (const audioTrack of audioTracks) {
if (audioTrack.label == label) {
trackMatch = audioTrack;
}
}
if (trackMatch) {
this.switchHtml5Track_(trackMatch);
}
Comment on lines +4312 to +4323
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: Is there any reason we use for/of over built in Array methods?

      const trackMatch = Array.from(this.video_.audioTracks)
                           .find(track => track.label == label);

      if (trackMatch) {
        this.switchHtml5Track_(trackMatch);
      }

Copy link
Member Author

Choose a reason for hiding this comment

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

I have done it like this for consistency with the rest of the code

Copy link
Member Author

Choose a reason for hiding this comment

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

@joeyparrish what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment really was just a curiosity. I don't see anything wrong with this.

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 know if it matters or not. I seem to recall that callback-based methods might have a performance penalty, maybe use more memory, I don't know. We used to do a lot of array.forEach() when the codebase was all ES5, but there was some issue that caused us to go to for-of when we upgraded to ES6+. I really can't recall what it was, and I could be misremembering the whole thing. I won't make it a policy to use one style or the other without a very good reason, and I can't remember a reason.

}
}

Expand Down