Skip to main content
Skip table of contents

Multi-audio

To test this feature and view the example code, please see the (5.33.x) 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 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 (5.33.x) Provide a preferred language for audio/subtitle tracks.

JavaScript errors detected

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

If this problem persists, please contact our support.