mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
17 lines
659 B
TypeScript
17 lines
659 B
TypeScript
/** Find the `<track>` element that owns the given `TextTrack`. */
|
|
export function findTrackElement(media: HTMLMediaElement, track: TextTrack): HTMLTrackElement | null {
|
|
for (const el of media.querySelectorAll?.('track') ?? []) {
|
|
if (el.track === track) return el;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getTextTrackList(media: HTMLMediaElement, filterPred: (textTrack: TextTrack) => boolean): TextTrack[] {
|
|
if (!media?.textTracks) return [];
|
|
return (Array.from(media.textTracks) as TextTrack[]).filter(filterPred).sort(sortByTextTrackKind);
|
|
}
|
|
|
|
function sortByTextTrackKind(a: TextTrack, b: TextTrack): number {
|
|
return a.kind >= b.kind ? 1 : -1;
|
|
}
|