Skip to main content
Version: 11.7.0

How to programmatically enable or disable audio tracks on Android

This article describes how you can use the AudioTrack API, a sub-API of the MediaTrack API, to enable or disable audio tracks. Implementing this functionality is a common use-case for developers who want to build their own UI to toggle audio languages on and off.

Once you have programmatically selected a track, you can set its enabled property (or method) to true or false. Because only one audio track can play at a time, enabling an audio track automatically disables all other audio tracks. Note that this does not apply to text tracks: multiple text tracks can be active at the same time.

Usage

The Android SDK exposes the audio tracks through player.getAudioTracks(), which contains MediaTrack objects with a setEnabled method.

// enable a specific audio track
player.audioTracks.getItem(indexOfRequestedAudioTrack).isEnabled = true