Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, number>> = {};
Expand All @@ -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 });
}
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/core/api/tracks_management/track_choice_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/public_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator Author

@peaBerberian peaBerberian Apr 4, 2023

Choose a reason for hiding this comment

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

Doing this just makes it more easy to catch issues (? meaning the absence of a field, whereas | undefined meaning that it has to be set explicitely to undefined)

id : number|string; }

/**
Expand Down