When a DASH stream contains multiple video tracks (indicated by multiple video Adaptation Sets in its manifest), you can switch between them using methods on the OTVVideoView instance. Video track selection is not supported for HLS streams.

For clarity, here, the term video track refers to a DASH Adaptation Set represented by an OTVTrackInfo object.

OTVTrackInfo[] getOTVTrackInfo()
JAVA

This returns an array comprising all of the stream’s audio and subtitle tracks and all supported video tracks.

Prerequisites

  • The player has been created, and the application is configured for watching clear content.
  • A clear stream containing more than one video Adaptation Set is available for testing.

Example code

The following example code is used to select video tracks. 

Video tracks are located by interrogating for tracks of type MEDIA_TRACK_TYPE_VIDEO.

    OTVTrackInfo[] trackInfo = mOTVVideoView.getOTVTrackInfo();
    for (int i = 0; i < trackInfo.length ; i++) {
      if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_VIDEO) {
        // Add to video track list with index 'i'
      } else if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_AUDIO) {
        // Ignore track
      } else if (trackInfo[i].getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT) {
        // Ignore track
      }
    }
    // Return video track list and indexes to present to the user for selection
JAVA

OTVVideoView.getOTVTrackInfo() will only return video tracks that the device can support

To select a track at an index of the array returned by getOTVTrackInfo().

mOTVVideoView.selectTrack(index);
JAVA

To deselect a track at an index of the array returned by getOTVTrackInfo().

mOTVVideoView.deselectTrack(index);
JAVA

Deselecting the current track is not necessary before selecting another track.

Additional track information

The OTVTrackInfo class contains additional information about video tracks, each representing a video Adaptation Set extracted from the stream’s manifest. It provides the following methods:

  • isActive() returns true for the selected track, and false for all other video tracks in the list
  • getName() provides a string describing the track (which may be simply the language)
  • getLanguage() provides the language code string in either way of ISO-639-1 or ISO-639-2
  • getEncodeType() always returns 0 for video tracks - the codecs of the underlying video tracks must be retrieved via OTVVideoTrackInfo.getCodecs() - a list of the track’s underlying OTVVideoTrackInfo objects is retrieved via the getVideoTrackInfos() method
  • getCharacteristics() returns a string of track characteristics as advertised in some HLS streams.
  • getVideoTrackInfos() returns a list of OTVVideoTrackInfo objects. Each OTVVideoTrackInfo object corresponds to one of the video Representations belonging to the Adaptation Set for which this OTVTrackInfo holds information. Each Representation - and therefore each OTVVideoTrackInfo - may contain data on resolution, bitrate, framerate and aspect ratio.

The OTVVideoTrackInfo class contains the following methods for retrieving data about a Representation:

  • getBitrate() returns the video Representation’s bitrate
  • getWidth() returns the video Representation’s width in pixels
  • getHeight() returns the video Representation’s height in pixels
  • getFrameRate() returns the video Representation’s framerate
  • getCodecs() returns a string listing the video Representation’s codecs or null if unknown
  • getPixelWidthHeightRatio() returns the video Representation’s floating-point width-to-height ratio, or 1.0 if unknown
OTVTrackInfo[] tracks = mPlayer.getOTVTrackInfo();
int selectedTrackIndex = -1;
for (int index = 0; index < tracks.size(); ++index) {
  OTVTrackInfo trackInfo = tracks.valueAt(index);
  if (trackInfo.getType() == OTVTrackInfo.MEDIA_TRACK_TYPE_VIDEO) {
    // Video track
    if (trackInfo.isActive()) {
      selectedTrackIndex = index;
    }
    StringBuilder trackNameBuilder = track.getName().equals("") ?
        String.format(Locale.ENGLISH, "Track %d",index + 1) :
        track.getName();
    String semiColon = "";
    List<OTVVideoTrackInfo> videoTrackInfos = track.getVideoTrackInfos();
    if (videoTrackInfos != null) {
      for (OTVVideoTrackInfo videoTrackInfo : videoTrackInfos) {
        sb.append(semiColon);
        semiColon = "; ";
        sb.append(String.format(Locale.ENGLISH, "Bitrate: %d, Res: %dx%d, Codecs: %s", 
        videoTrackInfo.getBitrate(),
        videoTrackInfo.getWidth(),
        videoTrackInfo.getHeight(),
        videoTrackInfo.getCodecs()));
      }
    }
    String trackName = trackNameBuilder.toString();
    ...
  }
}
JAVA

See also the Multi-audio and Subtitles features.