Skip to main content
Skip table of contents

Track selection

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

Track selection enables different audio tracks to be played, or subtitles to be displayed when a stream is playing. 

NMPTrackInfo getTrackInfo returns an array of all tracks in the current stream, including audio and subtitle tracks.

The audio track types that are supported are:

  • AAC-LC
  • HE-AAC
  • HE-AACv2

The subtitle track types are supported:

  • CC608
  • CC708
  • WebVTT
  • SMPTE-TT over ID3

Prerequisites

A clear stream is available for testing.

Example code

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

JAVA
NMPTrackInfo[] trackInfo = mNMPVideoView.getTrackInfo();
for( int i = 0; i < trackInfo.length ; i++ )
{
  if( trackInfo[ i ].getType() == NMPTrackType.NMP_TRACK_TYPE_AUDIO )
  {
    // add to audio track list with index ‘i’
  }
  else if( trackInfo[ i ].getType() == NMPTrackType.NMP_TRACK_TYPE_TIMEDTEXT )
  {
    // add to subtitle track list with index ‘i’
  }
}
//return text track list and indexes to present to the user for selection

To select an audio or subtitle track at an index of the array returned by getTrackInfo():

JAVA
selectTrack(int xIndex)

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

To deselect an audio or subtitle track at an index of the array returned by getTrackInfo() (optional):

JAVA
deselectTrack(int xIndex)

To implement a listener detecting track changes (optional), you need to set up a MediaPlayer.OnInfoListener listener:

JAVA
MediaPlayer.OnInfoListener mOnInfoListener = new MediaPlayer.OnInfoListener() {
  @Override
  public boolean onInfo(MediaPlayer mp, int what, int extra) {
    if (what == NMPMediaPlayer.MEDIA_INFO_METADATA_UPDATE && extra == NMPMediaPlayer.MEDIA_INFO_METADATA_EXTRA_TRACKS_CHANGED) {
      NMPTrackInfo[] tracks = mNMPVideoView.getNMPTrackInfo();
      // Do somethings with the tracks retrieved, e.g. Store the tracks info somewhere
    }
    return true;
  }
};

The listener with the implemented callback above should then be assigned to your NMPVideoView instance:

JAVA
mNMPVideoView.setOnInfoListener(mOnInfoListener);
JavaScript errors detected

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

If this problem persists, please contact our support.