logo

How to programmatically detect audio tracks

This article describes how you can use the API to detect audio tracks.

The AudioTrack API, which is a sub-API of the MediaTrack 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 audio 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 MediaTrack API.

function handleAddTrackEvent(addTrackEvent) {
    var audioTrack = addTrackEvent.track;
}
player.audioTracks.addEventListener('addtrack', handleAddTrackEvent);
Android (TV) SDK

The Android SDK leverages the MediaTrack API.

EventListener<AddTrackEvent> handleAddTrackEvent= new EventListener<AddTrackEvent>() {
    @Override
    public void handleEvent(AddTrackEvent addTrackEvent) {
        MediaTrack audioTrack = addTrackEvent.getTrack();
    }
};
tpv.getPlayer().getAudioTracks().addEventListener(AudioTrackListEventTypes.ADDTRACK, handleAddTrackEvent);
iOS (/tvOS) SDK

The iOS SDK leverages the MediaTrack API.

func handleAddTrackEvent(addTrackEvent : AddTrackEvent) {
    var audioTrack = addTrackEvent .track
}
self.theoplayer.audioTracks.addEventListener(type: AudioTrackListEventTypes.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
Singapore
Barcelona