Subtitles

Subtitles can be displayed when a stream is playing by calling the following methods.

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.

Example code

  • The subtitle tracks are located 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
    
  • To select a track at an index of the array returned by getTrackInfo():

    selectTrack(int xIndex)
    
  • To deselect a track at an index of the array returned by getTrackInfo() (optional):

    deselectTrack(int xIndex)
    
  • To implement a listener (ITrackChangedListener) that will be called whenever the track changes (optional):

    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.