logo

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.

Table of Contents

SDKs

Web SDK Android SDK iOS SDK tvOS SDK Android TV SDK Chromecast SDK
Yes Yes Yes Yes Yes Yes

Code examples

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

Web 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>() {
    @Override
    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)

Remarks

github
Make sure to follow us on GitHub!
THEO-logo-white
twitter
facebook
linkedin
Copyright © 2020. All Rights Reserved.
Leuven
New York
San Francisco
Singapore
Barcelona