Version: 2.67.0

How to programmatically enable or disable text tracks?

This article describes how you can use the API to enable or disable subtitles, closed captions or metadata.

The TextTracks API can be used to implement this functionality. Implementing this functionality is a common use-case for developers who want to build their own UI to toggle subtitles.


Web SDKAndroid SDKiOS SDKtvOSAndroid TV SDKChromecast SDK

Code examples

The code examples below how to implement toggling subtitles across SDK. It's advised to disable text tracks you don't want to display, in order to avoid issues with overlapping text.


// disable all text tracks
player.textTracks.forEach(function(track) {
track.mode = "disabled";
// enable a specific text track
player.textTracks[indexOfRequestedTextTrack].mode = "showing";

Android (TV) SDK

// disable all text tracks
for (int i = 0; i < tpv.getPlayer().getTextTracks().length(); i++) {
// enable a specific text track

iOS (/tvOS) SDK

// disable all text tracks
for i in 0..<self.player.textTracks.count {
var track = self.player.textTracks[i].mode = TextTrackMode.disabled
// enable a specific text track
self.player.textTracks[indexOfRequestedTextTrack].mode = TextTrackMode.showing