Version: 2.67.0

How to programmatically detect text tracks?

This article describes how you can use the API to detect text tracks, which can be subtitles, closed captions or metadata.

The TextTrack 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 visualize the available text languages.


Web SDKAndroid SDKiOS SDKtvOSAndroid TV SDKChromecast SDK

Code examples

The code examples below how to implement the detection of audio tracks across SDK.


The Web SDK leverages the TextTrack API.

function handleAddTrackEvent(addTrackEvent) {
var textTrack = addTrackEvent.track;
player.textTracks.addEventListener("addtrack", handleAddTrackEvent);

Android (TV) SDK

The Android SDK leverages the TextTrack API.

EventListener<AddTrackEvent> handleAudioTrackAdd = new EventListener<AddTrackEvent>() {
public void handleEvent(AddTrackEvent addTrackEvent) {
TextTrack textTrack = addTrackEvent.getTrack();
tpv.getPlayer().getTextTracks().addEventListener(TextTrackListEventTypes.ADDTRACK, handleAudioTrackAdd);

iOS (/tvOS) SDK

The iOS SDK leverages the MediaTrack API.

func handleAddTrackEvent(addTrackEvent : AddTrackEvent) {
var textTrack = addTrackEvent.track
self.theoplayer.textTracks.addEventListener(type: TextTrackListEventTypes.ADD_TRACK, listener: handleAddTrackEvent)`