SubtitleData
public
final
class
SubtitleData
extends Object
| java.lang.Object | |
| ↳ | androidx.media2.SubtitleData |
Class encapsulating subtitle data, as received through the
MediaPlayer.PlayerCallback.onSubtitleData(MediaPlayer, MediaItem, SubtitleData) 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.
MediaPlayer.TrackInfo of the subtitle track, one of
MIMETYPE_TEXT_CEA_608, MIMETYPE_TEXT_CEA_708,
MIMETYPE_TEXT_VTT.
Here is an example of iterating over the tracks of a MediaPlayer, and checking which
encoding is used for the subtitle tracks:
MediaPlayer mp = new MediaPlayer(context);
// prepare the player with a valid media item.
…
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 (SubtitleData.MIMETYPE_TEXT_CEA_608.equals(mime) {
// subtitle encoding is CEA 608
} else if (SubtitleData.MIMETYPE_TEXT_CEA_708.equals(mime) {
// subtitle encoding is CEA 708
} else if (SubtitleData.MIMETYPE_TEXT_VTT.equals(mime) {
// subtitle encoding is WebVTT
}
}
}
See also:
Summary
Constants | |
|---|---|
String |
MIMETYPE_TEXT_CEA_608
MIME type for CEA-608 closed caption data. |
String |
MIMETYPE_TEXT_CEA_708
MIME type for CEA-708 closed caption data. |
String |
MIMETYPE_TEXT_VTT
MIME type for WebVTT subtitle data. |
Public methods | |
|---|---|
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
|
getTrackIndex()
Returns the index of the MediaPlayer track which contains this subtitle data. |
Inherited methods | |
|---|---|
Constants
MIMETYPE_TEXT_CEA_608
public static final String MIMETYPE_TEXT_CEA_608
MIME type for CEA-608 closed caption data.
Constant Value: "text/cea-608"
MIMETYPE_TEXT_CEA_708
public static final String MIMETYPE_TEXT_CEA_708
MIME type for CEA-708 closed caption data.
Constant Value: "text/cea-708"
MIMETYPE_TEXT_VTT
public static final String MIMETYPE_TEXT_VTT
MIME type for WebVTT subtitle data.
Constant Value: "text/vtt"
Public methods
getData
public byte[] getData ()
Returns the encoded data for the subtitle content. Encoding format depends on the subtitle type, refer to CEA 708, CEA/EIA 608 and WebVTT, defined by the MIME type of the subtitle track.
| Returns | |
|---|---|
byte[] |
the encoded subtitle data |
getDurationUs
public long getDurationUs ()
Returns the duration in microsecond during which the subtitle should be displayed.
| Returns | |
|---|---|
long |
the display duration for the subtitle |
getStartTimeUs
public long getStartTimeUs ()
Returns the media time at which the subtitle should be displayed, expressed in microseconds.
| Returns | |
|---|---|
long |
the display start time for the subtitle |
getTrackIndex
public int getTrackIndex ()
Returns the index of the MediaPlayer track which contains this subtitle data.
| Returns | |
|---|---|
int |
an index in the array returned by MediaPlayer.getTrackInfo().
|
Interfaces
Classes
- CallbackMediaItem
- CallbackMediaItem.Builder
- DataSourceCallback
- FileMediaItem
- FileMediaItem.Builder
- HeartRating
- MediaBrowser
- MediaBrowser.BrowserCallback
- MediaBrowser.BrowserResult
- MediaController
- MediaController.ControllerCallback
- MediaController.ControllerResult
- MediaController.PlaybackInfo
- MediaItem
- MediaItem.Builder
- MediaLibraryService
- MediaLibraryService.LibraryParams
- MediaLibraryService.LibraryParams.Builder
- MediaLibraryService.LibraryResult
- MediaLibraryService.MediaLibrarySession
- MediaLibraryService.MediaLibrarySession.Builder
- MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback
- MediaMetadata
- MediaMetadata.Builder
- MediaPlayer
- MediaPlayer.PlayerCallback
- MediaPlayer.TrackInfo
- MediaSession
- MediaSession.Builder
- MediaSession.CommandButton
- MediaSession.CommandButton.Builder
- MediaSession.ControllerInfo
- MediaSession.SessionCallback
- MediaSession.SessionResult
- MediaSessionManager
- MediaSessionService
- MediaSessionService.MediaNotification
- MediaTimestamp
- PercentageRating
- PlaybackParams
- PlaybackParams.Builder
- SessionCommand
- SessionCommandGroup
- SessionCommandGroup.Builder
- SessionPlayer
- SessionPlayer.PlayerCallback
- SessionPlayer.PlayerResult
- SessionToken
- StarRating
- SubtitleData
- ThumbRating
- TimedMetaData
- UriMediaItem
- UriMediaItem.Builder
- VideoSize