Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/media/SubtitleData#pubctors) \| [Methods](https://developer.android.com/reference/android/media/SubtitleData#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/SubtitleData#inhmethods)

# SubtitleData

*** ** * ** ***


`
public

final

class
SubtitleData
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.SubtitleData |

<br />

*** ** * ** ***

Class encapsulating subtitle data, as received through the
`https://developer.android.com/reference/android/media/MediaPlayer.OnSubtitleDataListener` interface.
The subtitle data includes:

- the track index
- 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 `https://developer.android.com/reference/android/media/MediaPlayer.TrackInfo` of the subtitle track, one of `https://developer.android.com/reference/android/media/MediaFormat#MIMETYPE_TEXT_CEA_608`, `https://developer.android.com/reference/android/media/MediaFormat#MIMETYPE_TEXT_CEA_708`, `https://developer.android.com/reference/android/media/MediaFormat#MIMETYPE_TEXT_VTT`.


Here is an example of iterating over the tracks of a `https://developer.android.com/reference/android/media/MediaPlayer`, and checking which
encoding is used for the subtitle tracks:


```
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(myContentLocation);
mp.prepare(); // synchronous prepare, ready to use when method returns
final TrackInfo[] trackInfos = mp.getTrackInfo();
for (TrackInfo info : trackInfo) {
    if (info.getTrackType() == TrackInfo.MEDIA_TRACK_TYPE_SUBTITLE) {
        final String mime = info.getFormat().getString(MediaFormat.KEY_MIME);
        if (MediaFormat.MIMETYPE_TEXT_CEA_608.equals(mime) {
            // subtitle encoding is CEA 608
        } else if (MediaFormat.MIMETYPE_TEXT_CEA_708.equals(mime) {
            // subtitle encoding is CEA 708
        } else if (MediaFormat.MIMETYPE_TEXT_VTT.equals(mime) {
            // subtitle encoding is WebVTT
        }
    }
}
```


See
`https://developer.android.com/reference/android/media/MediaPlayer#setOnSubtitleDataListener(android.media.MediaPlayer.OnSubtitleDataListener,%20android.os.Handler)`
to receive subtitle data from a MediaPlayer object.
**See also:**

- `https://developer.android.com/reference/android/media/MediaPlayer`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/SubtitleData#SubtitleData(int,%20long,%20long,%20byte[])(int trackIndex, long startTimeUs, long durationUs, byte[] data) ` Constructor. |

| ### Public methods ||
|---|---|
| ` byte[]` | ` https://developer.android.com/reference/android/media/SubtitleData#getData()() ` Returns the encoded data for the subtitle content. |
| ` long` | ` https://developer.android.com/reference/android/media/SubtitleData#getDurationUs()() ` Returns the duration in microsecond during which the subtitle should be displayed. |
| ` long` | ` https://developer.android.com/reference/android/media/SubtitleData#getStartTimeUs()() ` Returns the media time at which the subtitle should be displayed, expressed in microseconds. |
| ` int` | ` https://developer.android.com/reference/android/media/SubtitleData#getTrackIndex()() ` Returns the index of the media player track which contains this subtitle data. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### SubtitleData

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public SubtitleData (int trackIndex, 
                long startTimeUs, 
                long durationUs, 
                byte[] data)
```

Constructor.

<br />

| Parameters ||
|---|---|
| `trackIndex` | `int`: the index of the media player track which contains this subtitle data. <br /> |
| `startTimeUs` | `long`: the start time in microsecond for the subtitle data <br /> |
| `durationUs` | `long`: the duration in microsecond for the subtitle data <br /> |
| `data` | `byte`: the data array for the subtitle data. It should not be null. No data copying is made. <br /> |

## Public methods

### getData

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public byte[] getData ()
```

Returns the encoded data for the subtitle content.
Encoding format depends on the subtitle type, refer to
[CEA 708](https://en.wikipedia.org/wiki/CEA-708),
[CEA/EIA 608](https://en.wikipedia.org/wiki/EIA-608) and
[WebVTT](https://www.w3.org/TR/webvtt1/), defined by the MIME type
of the subtitle track.

<br />

| Returns ||
|---|---|
| `byte[]` | the encoded subtitle data. This value cannot be `null`. <br /> |

### getDurationUs

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getDurationUs ()
```

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

<br />

| Returns ||
|---|---|
| `long` | the display duration for the subtitle <br /> |

### getStartTimeUs

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getStartTimeUs ()
```

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

<br />

| Returns ||
|---|---|
| `long` | the display start time for the subtitle <br /> |

### getTrackIndex

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getTrackIndex ()
```

Returns the index of the media player track which contains this subtitle data.

<br />

| Returns ||
|---|---|
| `int` | an index in the array returned by `https://developer.android.com/reference/android/media/MediaPlayer#getTrackInfo()`. <br /> |