Skip to main content
Skip table of contents

Multi-audio

To test this feature and view the example code, please see the Android SDK 5 Example Code Quick Start guide.

Different audio tracks can be enabled when a stream is playing by calling the following methods on the OTVVideoView instance. Multi-audio uses the same classes and methods as the Subtitles feature. However, getAudioChannelCount() only returns a valid value for audio tracks. In addition, there is always one audio track selected, whereas it is possible for no subtitle track to be selected. OTVTrackInfo[] getOTVTrackInfo() returns an array of all tracks in the current stream, including audio and subtitle tracks.

The following audio track types are supported:

  • AAC-LC

  • HE-AAC

  • HE-AACv2

  • AC3 (on some devices)

Prerequisites

A clear stream with an alternative audio track is available for testing.

Example code

The following example code is used to enable multi-audio tracks.

Audio tracks are located by interrogating for tracks of type AUDIO.

JAVA
    OTVTrackInfo[] trackInfo = mOTVVideoView.getOTVTrackInfo();
    for (int i = 0; i < trackInfo.length ; i++) {
      if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_AUDIO) {
        // Add to audio track list with index 'i'
      } else if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT) {
        // Ignore track
      } else if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_VIDEO) {
        // Ignore track
      }
    }
    // Return audio track list and indexes to present to the user for selection

To select a track at an index of the array returned by getOTVTrackInfo().

JAVA
mOTVVideoView.selectTrack(index);

Do not call selectTrack() if there is only one audio track as it is not supported and can lead to unexpected results.

To deselect a track at an index of the array returned by getTrackInfo() (optional).

JAVA
mOTVVideoView.deselectTrack(index);

To implement a listener (ITrackChangedListener) which is called whenever the track changes (optional)

JAVA
    mOTVVideoView.registerOnTrackChangedListener(mTrackchangedListener);
    // Create a Track changed listener
    private ITrackChangedListener mTrackchangedListener = new ITrackChangedListener() {
      @Override
      public void onTrackChanged() {
        // handle anything you want to do when a streams track changes
      }
    };

For details of the API calls used above, see the OTVVideoView class reference.

Default audio track selection in DASH streams

When multiple audio tracks exist, the default audio track will be selected in the following order:

  1. The role value is defined as main in the audio AdaptationSet.  The default role value is main if no role value is defined in the AdaptationSet.

  2. The audio track which matches the current system locale language.

  3. Technical track selection constraints (for example, hardware-accelerate decoder, maximum channel number ).

To override the default language selection, see Provide a preferred language for audio/subtitle tracks.

Additional track information

The OTVTrackInfo class contains additional information about audio tracks, each representing an audio Adaptation Set extracted from the stream’s manifest. It provides the following methods:

  • isActive() returns true for the selected track, and false for all other audio tracks in the list

  • getName() provides a string describing the track (which may be simply the language)

  • getLanguage() provides the language code string in either the ISO-639-1 or ISO-639-2 format

  • getEncodeType() returns an integer representing the audio encoding (see the reference API of OTVTrackInfo for the various values)

  • getCharacteristics() returns a string of track characteristics as advertised in some HLS streams. For audio tracks, this may include "public.accessibility.describes-video"

  • getMimeType() will return the MIME type of the audio track

  • getAudioChannelCount() will return the number of audio channels in the track 

  • getVideoTrackInfos() will return null for audio tracks

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.