Skip to content

Commit

Permalink
fix(FEC-11467): caption selection changes across entries in playlists (
Browse files Browse the repository at this point in the history
…#594)

**issue:**
when playing a playlist which its entries have at least 2 matching prefix of key languages (i.e. "zh" and "zh_tw"), and switching from one entry to another, the caption selection in player changes.

**solution:**
adding equality check in langComparer().
first seeking for an identical caption language, then for prefix.

Solves [FEC-11467](https://kaltura.atlassian.net/browse/FEC-11467)
  • Loading branch information
lianbenjamin authored Aug 8, 2021
1 parent acf4e1a commit b7d3134
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2507,12 +2507,20 @@ export default class Player extends FakeEventTarget {
* @private
*/
_setDefaultTrack<T: TextTrack | AudioTrack>(tracks: Array<T>, language: string, defaultTrack: ?Track): void {
const track: ?T = tracks.find(track => Track.langComparer(language, track.language));
if (track) {
const updateTrack = track => {
this.selectTrack(track);
this._markActiveTrack(track);
} else if (defaultTrack && !defaultTrack.active) {
this.selectTrack(defaultTrack);
};
const sameTrack: ?T = tracks.find(track => Track.langComparer(language, track.language, true));
if (sameTrack) {
updateTrack(sameTrack);
} else {
const track: ?T = tracks.find(track => Track.langComparer(language, track.language, false));
if (track) {
updateTrack(track);
} else if (defaultTrack && !defaultTrack.active) {
this.selectTrack(defaultTrack);
}
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/track/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ export default class Track {
* Comparing language strings.
* @param {string} inputLang - The configured language.
* @param {string} trackLang - The default track language.
* @param {boolean} equal - Optional flag to check for matching languages.
* @returns {boolean} - Whether the strings are equal or starts with the same substring.
*/
static langComparer(inputLang: string, trackLang: string): boolean {
static langComparer(inputLang: string, trackLang: string, equal: ?boolean): boolean {
try {
inputLang = inputLang.toLowerCase();
trackLang = trackLang.toLowerCase();
return inputLang ? inputLang.startsWith(trackLang) || trackLang.startsWith(inputLang) : false;
if (equal) {
return inputLang ? inputLang === trackLang : false;
} else {
return inputLang ? inputLang.startsWith(trackLang) || trackLang.startsWith(inputLang) : false;
}
} catch (e) {
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions test/src/track/track.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ describe('Track', () => {
it('should return false if the input lang is empty', () => {
Track.langComparer('', 'rus').should.be.false;
});

it('should compare languages using equality flag', () => {
Track.langComparer('zh', 'zh', true).should.be.true;
Track.langComparer('zh_tw', 'zh', true).should.be.false;
Track.langComparer('zh_tw', 'zh', false).should.be.true;
});
});
});

0 comments on commit b7d3134

Please sign in to comment.