Show Menu
TOPICS×

Overview

Alternate audio allows you to switch among available audio tracks for a video track. Users can select their preferred language track when the video is played.
When TVSDK creates the MediaPlayerItem instance for the current video, it creates an AudioTrack item for each available audio track. The item contains a name property, which is a string that typically contains a user-recognizable description of the language of that track. The item also contains information about whether to use that track by default. When it is time to play the video, you can ask for a list of available audio tracks, optionally allow the user select a track, and set the video to play with the selected track.
Although rare, if an additional audio track becomes available after TVSDK creates the MediaPlayerItem , TVSDK fires a MediaPlayerItem.AUDIO_TRACK_UPDATED event.

Added APIs

The following APIs have been added to support alternate audio:
hasAlternateAudio
If the specified media has an alternate audio track, other than default track, this boolean function returns true . If there is no alternate audio track, the function returns false .
boolean hasAlternateAudio();

** getAudioTracks **
This function returns list of all the current available audio tracks in a specified media.
List<AudioTrack> getAudioTracks();

getSelectedAudioTrack
This function that returns the currently selected alternate audio track and properties such as language. The auto-selection of track can also be extracted.
AudioTrack getSelectedAudioTrack();

selectAudioTrack
This function selects an alternate audio track to play.
void selectAudioTrack(AudioTrack audioTrack);

For example:
private void onPrepared() { 
    // Select the AA track in PREPARED State 
    boolean hasAlternateAudio = _mediaPlayer.getCurrentItem().hasAlternateAudio(); 
    if(hasAlternateAudio) { 
        AudioTrack selectedAudioTrack =  
          _mediaPlayer.getCurrentItem().getSelectedAudioTrack(); 
 
        if (selectedAudioTrack == null) {  
            // Selecting default audio track  
            // If index is 1 it will select alternate audio track  
            selectedAudioTrack = _mediaPlayer.getCurrentItem().getAudioTracks().get(0);  
        } 
    } 
    _mediaPlayer.getCurrentItem().selectAudioTrack(selectedAudioTrack); 
}