Skip to content

Commit

Permalink
fix: selectAudioLanguage() should ignore unplayable variants (#6805)
Browse files Browse the repository at this point in the history
When restrictions are set, `selectAudioLanguage()` ignores them and may
suggest variant that is marked as unplayable.
  • Loading branch information
tykus160 authored Jun 12, 2024
1 parent 4ea9a44 commit 95590ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4834,6 +4834,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.currentAdaptationSetCriteria_.create(this.manifest_.variants);
let bestVariant = null;
for (const curVariant of set.values()) {
if (!shaka.util.StreamUtils.isPlayable(curVariant)) {
continue;
}
if (!bestVariant ||
diff(bestVariant, active) > diff(curVariant, active)) {
bestVariant = curVariant;
Expand Down
8 changes: 8 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,14 @@ describe('Player', () => {
expect(getActiveVariantTrack().roles).toContain('commentary');
});

it('selectAudioLanguage() ignores unplayable variants', () => {
player.configure({
restrictions: {minChannelsCount: 6},
});
player.selectAudioLanguage('es');
expect(getActiveVariantTrack().channelsCount).toBe(6);
});

it('selectAudioLanguage() respects selected audio codec', () => {
player.selectAudioLanguage('es', '', 0, 0, 'mp4a.40.2');
expect(getActiveVariantTrack().audioCodec).toBe('mp4a.40.2');
Expand Down

0 comments on commit 95590ad

Please sign in to comment.