public final class TextTrackRenderer extends SampleSourceTrackRenderer implements Handler.Callback
TrackRenderer for subtitles. Text is parsed from sample data using a
SubtitleParser. The actual rendering of each line of text is delegated to a
TextRenderer.
If no SubtitleParser instances are passed to the constructor, the subtitle type will be
detected automatically for the following supported formats:
WebvttParser)TtmlParser)SubripParser)Tx3gParser)To override the default parsers, pass one or more SubtitleParser instances to the
constructor. The first SubtitleParser that returns true from
SubtitleParser.canParse(String) will be used.
END_OF_TRACK_US, MATCH_LONGEST_US, STATE_ENABLED, STATE_PREPARED, STATE_RELEASED, STATE_STARTED, STATE_UNPREPARED, UNKNOWN_TIME_US| Constructor and Description |
|---|
TextTrackRenderer(SampleSource[] sources,
TextRenderer textRenderer,
Looper textRendererLooper,
SubtitleParser... subtitleParsers) |
TextTrackRenderer(SampleSource source,
TextRenderer textRenderer,
Looper textRendererLooper,
SubtitleParser... subtitleParsers) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doSomeWork(long positionUs,
long elapsedRealtimeUs,
boolean sourceIsReady)
|
protected long |
getBufferedPositionUs()
Returns an estimate of the absolute position in microseconds up to which data is buffered.
|
boolean |
handleMessage(Message msg) |
protected boolean |
handlesTrack(MediaFormat mediaFormat)
Returns whether this renderer is capable of handling the provided track.
|
protected boolean |
isEnded()
Whether the renderer is ready for the
ExoPlayer instance to transition to
ExoPlayer.STATE_ENDED. |
protected boolean |
isReady()
Whether the renderer is able to immediately render media from the current position.
|
protected void |
onDisabled()
Called when the renderer is disabled.
|
protected void |
onDiscontinuity(long positionUs)
Invoked when a discontinuity is encountered.
|
protected void |
onEnabled(int track,
long positionUs,
boolean joining)
Called when the renderer is enabled.
|
doPrepare, doSomeWork, getDurationUs, getFormat, getTrackCount, maybeThrowError, onReleased, readSource, seekTo, shiftInputPositiongetMediaClock, getState, handleMessage, onStarted, onStoppedpublic TextTrackRenderer(SampleSource source, TextRenderer textRenderer, Looper textRendererLooper, SubtitleParser... subtitleParsers)
source - A source from which samples containing subtitle data can be read.textRenderer - The text renderer.textRendererLooper - The looper associated with the thread on which textRenderer should be
invoked. If the renderer makes use of standard Android UI components, then this should
normally be the looper associated with the applications' main thread, which can be
obtained using ContextWrapper.getMainLooper(). Null may be passed if the
renderer should be invoked directly on the player's internal rendering thread.subtitleParsers - SubtitleParsers to parse text samples, in order of decreasing
priority. If omitted, the default parsers will be used.public TextTrackRenderer(SampleSource[] sources, TextRenderer textRenderer, Looper textRendererLooper, SubtitleParser... subtitleParsers)
sources - Sources from which samples containing subtitle data can be read.textRenderer - The text renderer.textRendererLooper - The looper associated with the thread on which textRenderer should be
invoked. If the renderer makes use of standard Android UI components, then this should
normally be the looper associated with the applications' main thread, which can be
obtained using ContextWrapper.getMainLooper(). Null may be passed if the
renderer should be invoked directly on the player's internal rendering thread.subtitleParsers - SubtitleParsers to parse text samples, in order of decreasing
priority. If omitted, the default parsers will be used.protected boolean handlesTrack(MediaFormat mediaFormat)
SampleSourceTrackRendererhandlesTrack in class SampleSourceTrackRenderermediaFormat - The format of the track.protected void onEnabled(int track,
long positionUs,
boolean joining)
throws ExoPlaybackException
TrackRendererThe default implementation is a no-op.
onEnabled in class SampleSourceTrackRenderertrack - The track for which the renderer is being enabled.positionUs - The player's current position.joining - Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException - If an error occurs.protected void onDiscontinuity(long positionUs)
SampleSourceTrackRendereronDiscontinuity in class SampleSourceTrackRendererpositionUs - The playback position after the discontinuity, or the position at which
the renderer is being enabled.protected void doSomeWork(long positionUs,
long elapsedRealtimeUs,
boolean sourceIsReady)
throws ExoPlaybackException
SampleSourceTrackRendererdoSomeWork in class SampleSourceTrackRendererpositionUs - The current media time in microseconds, measured at the start of the
current iteration of the rendering loop.elapsedRealtimeUs - SystemClock.elapsedRealtime() in microseconds,
measured at the start of the current iteration of the rendering loop.sourceIsReady - The result of the most recent call to
SampleSource.SampleSourceReader.continueBuffering(int, long).ExoPlaybackException - If an error occurs.protected void onDisabled()
throws ExoPlaybackException
TrackRendererThe default implementation is a no-op.
onDisabled in class SampleSourceTrackRendererExoPlaybackException - If an error occurs.protected long getBufferedPositionUs()
TrackRenderer
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
getBufferedPositionUs in class SampleSourceTrackRendererTrackRenderer.END_OF_TRACK_US if the track is fully buffered, or TrackRenderer.UNKNOWN_TIME_US if
no estimate is available.protected boolean isEnded()
TrackRendererExoPlayer instance to transition to
ExoPlayer.STATE_ENDED. The player will make this transition as soon as true is
returned by all of its TrackRenderers.
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
isEnded in class TrackRendererprotected boolean isReady()
TrackRenderer
If the renderer is in the TrackRenderer.STATE_STARTED state then returning true indicates that the
renderer has everything that it needs to continue playback. Returning false indicates that
the player should pause until the renderer is ready.
If the renderer is in the TrackRenderer.STATE_ENABLED state then returning true indicates that the
renderer is ready for playback to be started. Returning false indicates that it is not.
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
isReady in class TrackRendererpublic boolean handleMessage(Message msg)
handleMessage in interface Handler.Callback