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(FEC-12760): default track stream selected when config.playback.textLanguage !== 'auto' - Regression #688

Merged
merged 9 commits into from
Dec 26, 2022
16 changes: 8 additions & 8 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2588,9 +2588,10 @@ export default class Player extends FakeEventTarget {
*/
_setDefaultTracks(): void {
const activeTracks = this.getActiveTracks();
const defaultStreamTrack = this._getTextTracks().find(track => track.default);
const playbackConfig = this.config.playback;
const offTextTrack: ?Track = this._getTextTracks().find(track => TextTrack.langComparer(OFF, track.language));
const defaultLanguage = this._getLanguage<TextTrack>(this._getTextTracks(), playbackConfig.textLanguage, activeTracks.text);
const defaultLanguage = this._getLanguage<TextTrack>(this._getTextTracks(), playbackConfig.textLanguage, defaultStreamTrack);
const currentOrConfiguredTextLang =
!this._playbackAttributesState.textLanguage || this._playbackAttributesState.textLanguage === OFF
? defaultLanguage
Expand Down Expand Up @@ -2625,19 +2626,18 @@ export default class Player extends FakeEventTarget {
* @returns {string} - The track language to set by default.
*/
_getLanguage<T: TextTrack | AudioTrack>(tracks: Array<T>, configuredLanguage: string, defaultTrack: ?T): string {
let autoSelectedLanguage: string = '';
const defaultStreamTrack: string = tracks.find(track => track.default)?.language || '';
if (configuredLanguage === AUTO) {
let language = configuredLanguage;
if (language === AUTO) {
const localeTrack: ?T = tracks.find(track => Track.langComparer(Locale.language, track.language));
if (localeTrack) {
autoSelectedLanguage = localeTrack.language;
language = localeTrack.language;
} else if (defaultTrack && defaultTrack.language !== OFF) {
autoSelectedLanguage = defaultTrack.language;
language = defaultTrack.language;
} else if (tracks && tracks.length > 0) {
autoSelectedLanguage = tracks[0].language;
language = tracks[0].language;
}
}
return autoSelectedLanguage || configuredLanguage || defaultStreamTrack;
return language;
}

/**
Expand Down