Skip to main content
Version: 11.8.0

How to programmatically enable or disable text tracks on Roku

This article describes how you can use the TextTrack API to enable or disable subtitles, closed captions or metadata. Implementing this functionality is a common use-case for developers who want to build their own UI to toggle subtitles.

It is advised to disable the text tracks which you do not want to display, in order to avoid issues with overlapping text.

Usage

To disable all text tracks, iterate through all text tracks and set the mode field to disabled for each of them.

Note that in BrightScript and SceneGraph you have to assign a whole new associative array to the interface field in order to change the associative array exposed through the interface. Attempts to change fields of an associative array or elements of an array that are values of node fields have no effect.

'disable all tracks
textTracks = m.player.textTracks
for i = textTracks.count() - 1 to 0 step -1
textTracks[i].mode = "disabled"
end for
' Assignment of new roAssociativeArray is required, because Roku field values are copies, not references.
' Read more: https://developer.roku.com/en-gb/docs/developer-program/performance-guide/optimization-techniques.md#OptimizationTechniques-DataFlow
m.player.textTracks = textTracks

'disable specific track
textTracks = m.player.textTracks
textTracks[indexOfRequestedTextTrack].mode = "disabled"
m.player.textTracks = textTracks