Dynamically switching track (vtt) file while video is playing

1.3k Views Asked by At

I'm using VideoJS to load videos with captions. I'm hoping that there is a way in the api to dynamically switch from one .vtt caption file to another. I have a video with subtitles in both English and an alternate language. While the video is playing the visitor needs to toggle between either one.

Looking for something like:

_V_.Track.src="blah.vtt";

I suppose the alternate way would be to get the time position of the video and reload it with the other vtt.

Any suggestions would be appreciated.

1

There are 1 best solutions below

0
On

I'm looking to do something similar to this with a caption track... but have also not been able to find a clean way to accomplish the task.

The best I can do is something like this:

document.getElementById("HtmlFiveMediaPlayer_html5_api").innerHTML = '<track label="English Captions" srclang="en" kind="captions" src="http://localhost/media/captiontest/demo_Brian/demo_h264_1.vtt" type="text/vtt" default />';

Where I insert the HTML directly into the video tag... but this doesn't work well with the CC button in video-js (doesn't get added / created at all if the track wasn't there when the tag was loaded).