2

I have a video player with a track for captions:

<video ... >
<track src="/file.vtt" default kind="captions" srcLang="en" label="English" />
</video>

It loads and works great when the page loads, but I want to give users the ability to toggle/turn captions on and off with a custom button. I don't want to use the native video controls.

I tried:

btnClick(){
 //get track ref
 track.mode = "hidden"
}

Using javascript, but it's not doing anything.

How can I control the captions/track with javascript?

Will
  • 605
  • 2
  • 11
  • 23

1 Answers1

1

I figured it out. Instead of updating a reference to the track element, it's working if I use a reference to the video element.

let track = video.textTracks && video.textTracks[0]
if (track) track.mode = "hidden"
Will
  • 605
  • 2
  • 11
  • 23