Multi-audio

To enable different audio tracks, the following methods must be called when a stream is playing):

NMPTrackInfo[] getTrackInfo()

This 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

Prerequisites

  • The player must have been created.
  • The application must be configured for watching clear content.
  • You should have a clear stream with an alternative audio track available for testing.

Procedure

  1. Find the audio tracks by interrogating for tracks of type 'AUDIO'. For example:

    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 )
      {
        // ignore track
      }
    }
    //return text track list and indexes to present to the user for selection
    
  2. Select a track at an index of the array returned by getTrackInfo(). For example:

    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.

  3. You can optionally deselect a track at an index of the array returned by getTrackInfo(). For example:

    deselectTrack(int xIndex)
    
  4. You can also optionally implement a listener that will be called whenever the track changes (ITrackChangedListener). For example:

    mNMPVideoView.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
      }
    };
    

See the NMPVideoView class reference for details of the API calls used above.