Version: 2.67.0

How to dynamically change the visible captions?

When working with the captions / text-track options, you can dynamically change the currently selected language (or set a default language) using following methods.

This method assumes that you are using text-tracks that are loaded with the manifest. If you add the text-track separately, you can just use this API: Test Track Description API

Step-by-step guide

1.Create a new function inside the browser

function setLanguage(player, language) {
// Disable all text tracks that are currently active
player.textTracks
.filter(function(x) {
if (x.label !== "disabled") {
return x;
}
})
.forEach(function(x) {
x.mode = "disabled";
});
// Enable the text track for a specific language. Note: here i searched on the label, you can also do x.language for the ISO 3 letter language code
player.textTracks.filter(function(x) {
if (x.label == language) {
return x;
}
})[0].mode = "showing";
}
  1. Call the function using the language label (or 3-letter-language code if you change x.label to x.language)