diff --git a/src/core/api/tracks_management/media_element_track_choice_manager.ts b/src/core/api/tracks_management/media_element_track_choice_manager.ts index 73283c6276..199c83e524 100644 --- a/src/core/api/tracks_management/media_element_track_choice_manager.ts +++ b/src/core/api/tracks_management/media_element_track_choice_manager.ts @@ -120,10 +120,7 @@ function createAudioTracks( */ function createTextTracks( textTracks: ICompatTextTrackList -): Array<{ track: { id: string; - normalized: string; - language: string; - closedCaption: boolean; }; +): Array<{ track: ITextTrack; nativeTrack: TextTrack; }> { const newTextTracks = []; const languagesOccurences: Partial> = {}; @@ -137,10 +134,20 @@ function createTextTracks( "_" + occurences.toString(); languagesOccurences[language] = occurences + 1; - const track = { language: textTrack.language, - id, - normalized: normalizeLanguage(textTrack.language), - closedCaption: textTrack.kind === "captions" }; + + // Safari seems to be indicating that the subtitles track is a forced + // subtitles track by setting the `kind` attribute to `"forced"`. + // As of now (2023-04-04), this is not standard. + // @see https://github.com/whatwg/html/issues/4472 + const forced = (textTrack.kind as string) === "forced" ? + true : + undefined; + const track = { language: textTrack.language, + forced, + label: textTrack.label, + id, + normalized: normalizeLanguage(textTrack.language), + closedCaption: textTrack.kind === "captions" }; newTextTracks.push({ track, nativeTrack: textTrack }); } @@ -471,6 +478,8 @@ export default class MediaElementTrackChoiceManager public getAvailableTextTracks(): IAvailableTextTrack[] { return this._textTracks.map(({ track, nativeTrack }) => { return { id: track.id, + label: track.label, + forced: track.forced, language: track.language, normalized: track.normalized, closedCaption: track.closedCaption, diff --git a/src/core/api/tracks_management/track_choice_manager.ts b/src/core/api/tracks_management/track_choice_manager.ts index d8e90573be..f6b7b75b00 100644 --- a/src/core/api/tracks_management/track_choice_manager.ts +++ b/src/core/api/tracks_management/track_choice_manager.ts @@ -662,10 +662,8 @@ export default class TrackChoiceManager { closedCaption: chosenTextAdaptation.isClosedCaption === true, id: chosenTextAdaptation.id, label: chosenTextAdaptation.label, + forced: chosenTextAdaptation.isForcedSubtitles, }; - if (chosenTextAdaptation.isForcedSubtitles !== undefined) { - formatted.forced = chosenTextAdaptation.isForcedSubtitles; - } return formatted; } @@ -792,10 +790,8 @@ export default class TrackChoiceManager { active: currentId === null ? false : currentId === adaptation.id, label: adaptation.label, + forced: adaptation.isForcedSubtitles, }; - if (adaptation.isForcedSubtitles !== undefined) { - formatted.forced = adaptation.isForcedSubtitles; - } return formatted; }); } diff --git a/src/public_types.ts b/src/public_types.ts index a51ba54a27..bed8f24abf 100644 --- a/src/public_types.ts +++ b/src/public_types.ts @@ -765,8 +765,8 @@ export interface IAudioTrack { language : string; export interface ITextTrack { language : string; normalized : string; closedCaption : boolean; - forced? : boolean | undefined; - label? : string | undefined; + forced : boolean | undefined; + label : string | undefined; id : number|string; } /**