Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created May 15, 2021 18:23
Show Gist options
  • Save PatrickKalkman/0ef50b715a31ae0954a452cab2dfaafe to your computer and use it in GitHub Desktop.
Save PatrickKalkman/0ef50b715a31ae0954a452cab2dfaafe to your computer and use it in GitHub Desktop.
Loading and selecting subtitles
let captionUrl = "http://amssamples.streaming.mediaservices.windows.net/bc57e088-27ec-44e0-ac20-a85ccbcd50da/TOS-en.vtt";
this.player
.load(videoUrl)
.then(() => {
this.player.addTextTrackAsync(captionUrl, "en", "subtitle", 'text/vtt').then(() => {{
const textTracks = this.player.getTextTracks();
if (textTracks.length > 0) {
this.player.setTextTrackVisibility(true);
this.player.selectTextTrack(textTracks[0]);
}
this.videoElement?.play();
}});
})
.catch((e: any) => {
console.error(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment