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 features the same classes and calls as the Subtitles feature. However, there is always one audio track selected, whereas there can be no subtitles 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
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 bygetTrackInfo() (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.