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 located by interrogating for tracks of type AUDIO
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()
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)
mOTVVideoView.deselectTrack(index);
To implement a listener (ITrackChangedListener
) which is called whenever the track changes (optional)
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:
- 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.
- The audio track which matches the current system locale language.
- Technical track selection constraints (for example, hardware-accelerate decoder, maximum channel number ).
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()
returnstrue
for the selected track, andfalse
for all other audio tracks in the listgetName()
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 formatgetEncodeType()
returns an integer representing the audio encoding (see the reference API ofOTVTrackInfo
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 trackgetAudioChannelCount()
will return the number of audio channels in the trackgetVideoTrackInfos()
will returnnull
for audio tracks