public final class TextRenderer extends BaseRenderer implements Handler.Callback
Subtitle
s are decoded from sample data using SubtitleDecoder
instances obtained
from a SubtitleDecoderFactory
. The actual rendering of the subtitle Cue
s is
delegated to an TextRenderer.Output
.
Modifier and Type | Class and Description |
---|---|
static interface |
TextRenderer.Output
Receives output from a
TextRenderer . |
STATE_DISABLED, STATE_ENABLED, STATE_STARTED
ADAPTIVE_NOT_SEAMLESS, ADAPTIVE_NOT_SUPPORTED, ADAPTIVE_SEAMLESS, ADAPTIVE_SUPPORT_MASK, FORMAT_EXCEEDS_CAPABILITIES, FORMAT_HANDLED, FORMAT_SUPPORT_MASK, FORMAT_UNSUPPORTED_SUBTYPE, FORMAT_UNSUPPORTED_TYPE
Constructor and Description |
---|
TextRenderer(TextRenderer.Output output,
Looper outputLooper) |
TextRenderer(TextRenderer.Output output,
Looper outputLooper,
SubtitleDecoderFactory decoderFactory) |
Modifier and Type | Method and Description |
---|---|
boolean |
handleMessage(Message msg) |
boolean |
isEnded()
Whether the renderer is ready for the
ExoPlayer instance to transition to
ExoPlayer.STATE_ENDED . |
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 |
onPositionReset(long positionUs,
boolean joining)
Called when the position is reset.
|
protected void |
onStreamChanged(Format[] formats)
Called when the renderer's stream has changed.
|
void |
render(long positionUs,
long elapsedRealtimeUs)
Incrementally renders the
SampleStream . |
int |
supportsFormat(Format format)
Returns the extent to which the
Renderer supports a given format. |
disable, enable, getCapabilities, getIndex, getMediaClock, getState, getStream, getTrackType, handleMessage, hasReadStreamToEnd, isSourceReady, maybeThrowStreamError, onEnabled, onStarted, onStopped, readSource, replaceStream, resetPosition, setCurrentStreamIsFinal, setIndex, skipToKeyframeBefore, start, stop, supportsMixedMimeTypeAdaptation
public TextRenderer(TextRenderer.Output output, Looper outputLooper)
output
- The output.outputLooper
- The looper associated with the thread on which the output should be
called. If the output makes use of standard Android UI components, then this should
normally be the looper associated with the application's main thread, which can be obtained
using ContextWrapper.getMainLooper()
. Null may be passed if the output
should be called directly on the player's internal rendering thread.public TextRenderer(TextRenderer.Output output, Looper outputLooper, SubtitleDecoderFactory decoderFactory)
output
- The output.outputLooper
- The looper associated with the thread on which the output should be
called. If the output makes use of standard Android UI components, then this should
normally be the looper associated with the application's main thread, which can be obtained
using ContextWrapper.getMainLooper()
. Null may be passed if the output
should be called directly on the player's internal rendering thread.decoderFactory
- A factory from which to obtain SubtitleDecoder
instances.public int supportsFormat(Format format)
RendererCapabilities
Renderer
supports a given format. The returned value is
the bitwise OR of two properties:
RendererCapabilities.FORMAT_HANDLED
,
RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES
, RendererCapabilities.FORMAT_UNSUPPORTED_SUBTYPE
and
RendererCapabilities.FORMAT_UNSUPPORTED_TYPE
.RendererCapabilities.ADAPTIVE_SEAMLESS
, RendererCapabilities.ADAPTIVE_NOT_SEAMLESS
and
RendererCapabilities.ADAPTIVE_NOT_SUPPORTED
.RendererCapabilities.FORMAT_SUPPORT_MASK
and RendererCapabilities.ADAPTIVE_SUPPORT_MASK
respectively.supportsFormat
in interface RendererCapabilities
format
- The format.protected void onStreamChanged(Format[] formats) throws ExoPlaybackException
BaseRenderer
BaseRenderer.onEnabled(boolean)
has been called, and also when the stream has been replaced whilst
the renderer is enabled or started.
The default implementation is a no-op.
onStreamChanged
in class BaseRenderer
formats
- The enabled formats.ExoPlaybackException
- If an error occurs.protected void onPositionReset(long positionUs, boolean joining)
BaseRenderer
BaseRenderer.onStreamChanged(Format[])
has been called, and also when a position discontinuity
is encountered.
After a position reset, the renderer's SampleStream
is guaranteed to provide samples
starting from a key frame.
The default implementation is a no-op.
onPositionReset
in class BaseRenderer
positionUs
- The new playback position in microseconds.joining
- Whether this renderer is being enabled to join an ongoing playback.public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException
Renderer
SampleStream
.
If the renderer is in the Renderer.STATE_ENABLED
state then each call to this method will do
work toward being ready to render the SampleStream
when the renderer is started. It may
also render the very start of the media, for example the first frame of a video stream. If the
renderer is in the Renderer.STATE_STARTED
state then calls to this method will render the
SampleStream
in sync with the specified media positions.
This method should return quickly, and should not block if the renderer is unable to make useful progress.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
render
in interface Renderer
positionUs
- 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.ExoPlaybackException
- If an error occurs.protected void onDisabled()
BaseRenderer
The default implementation is a no-op.
onDisabled
in class BaseRenderer
public boolean isEnded()
Renderer
ExoPlayer
instance to transition to
ExoPlayer.STATE_ENDED
. The player will make this transition as soon as true
is
returned by all of its Renderer
s.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
public boolean isReady()
Renderer
If the renderer is in the Renderer.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 Renderer.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:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
public boolean handleMessage(Message msg)
handleMessage
in interface Handler.Callback