The OTVTrackInfo class contains additional information about the subtitle track, which can be attained through the class’s methods. Typically, that extra information is extracted from the stream’s manifest/playlist, so the availability of the information is dependent on the streams:
isActive() will return true for the selected track, and false for all other subtitle 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() returns an integer representing the subtitles’ encoding (see the reference API of OTVTrackInfo for the various values)
getCharacteristics() will return a string of track characteristics as advertised in some HLS streams.
getVideoTrackInfos() will return null for subtitle tracks
getMimeType() will return the MIME type for the track
getAudioChannelCount() will return -1 for subtitle tracks
Click here to view the example code.
JAVA
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_TIMEDTEXT) {
// Subtitles track
if (trackInfo.isActive()) {
selectedTrackIndex = index;
}
StringBuilder trackNameBuilder = track.getName().equals("") ?
String.format(Locale.ENGLISH,"Track %d",index + 1) :
track.getName();
trackNameBuilder.append(" <" + trackInfo.getLanguage() + ">");
String characteristics = track.getCharacteristics().toLowerCase();
if (!characteristics.isEmpty()) {
String[] characteristicsArray = characteristics.split(",");
for (String chrs : characteristicsArray) {
if (chrs.equalsIgnoreCase("public.accessibility.transcribes-spoken-dialog") ||
chrs.equalsIgnoreCase("public.accessibility.describes-music-and-sound") ||
chrs.equalsIgnoreCase("public.easy-to-read")) {
trackNameBuilder.append(" (Hard of Hearing)");
break;
}
}
}
String encodingType;
int et = track.getEncodeType();
switch (et) {
case OTVTrackInfo.SUBTITLE_TRACK_ENCODING_TYPE_DVB_BITMAP:
trackNameBuilder.append(" [DVB bitmap]");
break;
case OTVTrackInfo.SUBTITLE_TRACK_ENCODING_TYPE_EIA_608:
trackNameBuilder.append(" [CC608]");
break;
case OTVTrackInfo.SUBTITLE_TRACK_ENCODING_TYPE_EIA_708:
trackNameBuilder.append(" [CC708]");
break;
case OTVTrackInfo.SUBTITLE_TRACK_ENCODING_TYPE_ID3:
trackNameBuilder.append(" [ID3]");
break;
case OTVTrackInfo.SUBTITLE_TRACK_ENCODING_TYPE_WEBVTT:
trackNameBuilder.append(" [WebVTT]");
break;
case OTVTrackInfo.SUBTITLE_TRACK_ENCODING_TYPE_SRT:
trackNameBuilder.append(" [SRT]");
break;
case OTVTrackInfo.SUBTITLE_TRACK_ENCODING_TYPE_SMPTE:
trackNameBuilder.append(" [SMPTE]");
break;
default:
break;
}
String trackName = trackNameBuilder.toString();
...
}
}
JavaScript errors detected
Please note, these errors can depend on your browser setup.
If this problem persists, please contact our support.