SubtitleData

public final class SubtitleData
extends Object implements VersionedParcelable

java.lang.Object
   ↳ androidx.media2.common.SubtitleData


Class encapsulating subtitle data, as received through the SessionPlayer.PlayerCallback.onSubtitleData(SessionPlayer, MediaItem, SessionPlayer.TrackInfo, SubtitleData) interface. The subtitle data includes:

  • the start time (in microseconds) of the data
  • the duration (in microseconds) of the data
  • the actual data.
The data is stored in a byte-array, and is encoded in one of the supported in-band subtitle formats. The subtitle encoding is determined by the MIME type of the SessionPlayer.TrackInfo of the subtitle track, one of MediaFormat.MIMETYPE_TEXT_CEA_608 or MediaFormat.MIMETYPE_TEXT_CEA_708.

Here is an example of iterating over the tracks of a SessionPlayer, and checking which encoding is used for the subtitle tracks:

 // Initialize instance of player that extends SessionPlayer
 SessionPlayerExtension player = new SessionPlayerExtension();

 final TrackInfo[] trackInfos = player.getTrackInfo();
 for (TrackInfo info : trackInfo) {
     if (info.getTrackType() == TrackInfo.MEDIA_TRACK_TYPE_SUBTITLE) {
         final String mime = info.getFormat().getString(MediaFormat.KEY_MIME);
         if ("text/cea-608".equals(mime) {
             // subtitle encoding is CEA 608
         } else if ("text/cea-708".equals(mime) {
             // subtitle encoding is CEA 708
         }
     }
 }
 

Summary

Public constructors

SubtitleData(long startTimeUs, long durationUs, byte[] data)

Public methods

boolean equals(Object o)
byte[] getData()

Returns the encoded data for the subtitle content.

long getDurationUs()

Returns the duration in microsecond during which the subtitle should be displayed.

long getStartTimeUs()

Returns the media time at which the subtitle should be displayed, expressed in microseconds.

int hashCode()

Inherited methods