Subtitles

To enable subtitles to be displayed, 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 subtitle and audio tracks.

The subtitle track types that are supported are:

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

Prerequisites

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

Procedure

  1. Find the subtitle tracks by interrogating for tracks of type 'TIMEDTEXT'. For example:

    NMPTrackInfo[] trackInfo = mNMPVideoView.getTrackInfo();
    for( int i = 0; i < trackInfo.length ; i++ )
    {
      if( trackInfo[ i ].getType() == NMPTrackType.NMP_TRACK_TYPE_TIMEDTEXT )
      {
        // add to text track list with index ‘i’
      }
      else if( trackInfo[ i ].getType() == NMPTrackType.NMP_TRACK_TYPE_AUDIO )
      {
        // 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)
    
  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.