public class ExoplayerWrapper
extends java.lang.Object
implements com.google.android.exoplayer.ExoPlayer.Listener, com.google.android.exoplayer.chunk.ChunkSampleSource.EventListener, com.google.android.exoplayer.upstream.BandwidthMeter.EventListener, com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListener, com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListener, com.google.android.exoplayer.text.TextRenderer, com.google.android.exoplayer.drm.StreamingDrmSessionManager.EventListener, com.google.android.exoplayer.dash.DashChunkSource.EventListener, com.google.android.exoplayer.hls.HlsSampleSource.EventListener, com.google.android.exoplayer.metadata.MetadataTrackRenderer.MetadataRenderer<java.util.List<com.google.android.exoplayer.metadata.id3.Id3Frame>>
ExoPlayer
that provides a higher level interface. It can be prepared
with one of a number of ExoplayerWrapper.RendererBuilder
classes to suit different use cases (e.g. DASH,
SmoothStreaming and so on).Modifier and Type | Class and Description |
---|---|
static interface |
ExoplayerWrapper.CaptionListener
A listener for receiving notifications of timed text.
|
static interface |
ExoplayerWrapper.Id3MetadataListener
A listener for receiving ID3 metadata parsed from the media stream.
|
static interface |
ExoplayerWrapper.InfoListener
A listener for debugging information.
|
static interface |
ExoplayerWrapper.InternalErrorListener
A listener for internal errors.
|
static interface |
ExoplayerWrapper.PlaybackListener
A listener for basic playback events.
|
static interface |
ExoplayerWrapper.RendererBuilder
Builds renderers for the player.
|
static interface |
ExoplayerWrapper.TextListener
A listener for receiving notifications of timed text.
|
Modifier and Type | Field and Description |
---|---|
static int |
DISABLED_TRACK
This variable must be an int, not part of an enum because it has significance within the
Exoplayer library.
|
static int |
PRIMARY_TRACK
This variable must be an int, not part of an enum because it has significance within the
Exoplayer library.
|
static int |
RENDERER_COUNT
Exoplayer renderers are managed in an array (the array representation is used throughout the
Exoplayer library).
|
static int |
TRACK_DISABLED |
static int |
TYPE_AUDIO
The element at index TYPE_AUDIO is an audio type renderer.
|
static int |
TYPE_DEBUG
The element at index TYPE_DEBUG is a debug type renderer.
|
static int |
TYPE_METADATA |
static int |
TYPE_TEXT
The element at index TYPE_TEXT is a text type renderer.
|
static int |
TYPE_TIMED_METADATA
For id3 metadata.
|
static int |
TYPE_VIDEO
The element at index TYPE_VIDEO is a video type renderer.
|
Constructor and Description |
---|
ExoplayerWrapper(ExoplayerWrapper.RendererBuilder rendererBuilder) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(ExoplayerWrapper.PlaybackListener playbackListener)
Add a listener to respond to size change and error events.
|
void |
blockingClearSurface()
Clear the video surface.
|
boolean |
getBackgrounded() |
com.google.android.exoplayer.upstream.BandwidthMeter |
getBandwidthMeter() |
int |
getBufferedPercentage()
Returns the number of the milliseconds of the video that has been buffered.
|
com.google.android.exoplayer.CodecCounters |
getCodecCounters() |
long |
getCurrentPosition()
Returns the position of the seek head in the number of
milliseconds after the start of the video.
|
long |
getDuration()
Returns the duration of the video in milliseconds.
|
com.google.android.exoplayer.chunk.Format |
getFormat() |
int |
getPlaybackState()
Returns the state of the Exoplayer instance.
|
ObservablePlayerControl |
getPlayerControl()
Returns the player control which can be used to play, pause, seek, get elapsed time, and get
elapsed duration.
|
boolean |
getPlayWhenReady()
Returns true if the video is set to start as soon as it is set up, returns false otherwise.
|
int |
getSelectedTrack(int type) |
int |
getStateForTrackType(int type)
Returns whether the track is
PRIMARY_TRACK or {@link #DISABLED_TRACK). |
android.view.Surface |
getSurface()
Returns the surface on which the video is rendered.
|
java.lang.String[] |
getTracks(int type)
Returns the name of the track at the given index.
|
void |
onAudioTrackInitializationError(com.google.android.exoplayer.audio.AudioTrack.InitializationException e) |
void |
onAudioTrackUnderrun(int bufferSize,
long bufferSizeMs,
long elapsedSinceLastFeedMs) |
void |
onAudioTrackWriteError(com.google.android.exoplayer.audio.AudioTrack.WriteException e) |
void |
onAvailableRangeChanged(int sourceId,
com.google.android.exoplayer.TimeRange availableRange) |
void |
onBandwidthSample(int elapsedMs,
long bytes,
long bandwidthEstimate) |
void |
onCryptoError(android.media.MediaCodec.CryptoException e) |
void |
onCues(java.util.List<com.google.android.exoplayer.text.Cue> cues) |
void |
onDecoderInitializationError(com.google.android.exoplayer.MediaCodecTrackRenderer.DecoderInitializationException e) |
void |
onDecoderInitialized(java.lang.String decoderName,
long elapsedRealtimeMs,
long initializationDurationMs) |
void |
onDownstreamFormatChanged(int sourceId,
com.google.android.exoplayer.chunk.Format format,
int trigger,
long mediaTimeMs) |
void |
onDrawnToSurface(android.view.Surface surface) |
void |
onDrmKeysLoaded() |
void |
onDrmSessionManagerError(java.lang.Exception e) |
void |
onDroppedFrames(int count,
long elapsed) |
void |
onLoadCanceled(int sourceId,
long bytesLoaded) |
void |
onLoadCompleted(int sourceId,
long bytesLoaded,
int type,
int trigger,
com.google.android.exoplayer.chunk.Format format,
long mediaStartTimeMs,
long mediaEndTimeMs,
long elapsedRealtimeMs,
long loadDurationMs) |
void |
onLoadError(int sourceId,
java.io.IOException e) |
void |
onLoadStarted(int sourceId,
long length,
int type,
int trigger,
com.google.android.exoplayer.chunk.Format format,
long mediaStartTimeMs,
long mediaEndTimeMs) |
void |
onMetadata(java.util.List<com.google.android.exoplayer.metadata.id3.Id3Frame> metadata) |
void |
onPlayerError(com.google.android.exoplayer.ExoPlaybackException exception) |
void |
onPlayerStateChanged(boolean playWhenReady,
int state) |
void |
onPlayWhenReadyCommitted() |
void |
onRenderers(com.google.android.exoplayer.TrackRenderer[] renderers,
com.google.android.exoplayer.upstream.BandwidthMeter bandwidthMeter)
Invoked with the results from a
ExoplayerWrapper.RendererBuilder . |
void |
onRenderersError(java.lang.Exception e)
Notify the listeners when an exception is thrown.
|
void |
onUpstreamDiscarded(int sourceId,
long mediaStartTimeMs,
long mediaEndTimeMs) |
void |
onVideoSizeChanged(int width,
int height,
int unappliedRotationDegrees,
float pixelWidthHeightRatio) |
void |
prepare()
Build the renderers.
|
void |
release()
When you are finished using this object, make sure to call this method.
|
void |
removeListener(ExoplayerWrapper.PlaybackListener playbackListener)
Remove a listener from notifications about size changes and errors.
|
void |
seekTo(int positionMs)
Move the seek head to the given position.
|
void |
setBackgrounded(boolean backgrounded) |
void |
setCaptionListener(ExoplayerWrapper.CaptionListener listener) |
void |
setInfoListener(ExoplayerWrapper.InfoListener listener)
Set a listener to respond to media format changes, bandwidth samples, load events, and dropped
frames.
|
void |
setInternalErrorListener(ExoplayerWrapper.InternalErrorListener listener)
Set a listener to respond to errors within Exoplayer.
|
void |
setMetadataListener(ExoplayerWrapper.Id3MetadataListener listener) |
void |
setPlayWhenReady(boolean playWhenReady)
Set whether the player should begin as soon as it is setup.
|
void |
setSelectedTrack(int type,
int index) |
void |
setSurface(android.view.Surface surface) |
void |
setTextListener(ExoplayerWrapper.TextListener listener)
Set the listener which responds to incoming text (ex subtitles or captions).
|
public static final int RENDERER_COUNT
There are RENDERER_COUNT elements in the array.
public static final int TYPE_VIDEO
public static final int TYPE_AUDIO
public static final int TYPE_TEXT
public static final int TYPE_METADATA
public static final int TRACK_DISABLED
public static final int TYPE_TIMED_METADATA
public static final int TYPE_DEBUG
public static final int DISABLED_TRACK
public static final int PRIMARY_TRACK
public ExoplayerWrapper(ExoplayerWrapper.RendererBuilder rendererBuilder)
rendererBuilder
- Responsible for loading the data from the source, processing it,
and providing byte streams. By modifying the renderer builder, we can
support different video formats like DASH, MP4, and SmoothStreaming.public ObservablePlayerControl getPlayerControl()
public void addListener(ExoplayerWrapper.PlaybackListener playbackListener)
playbackListener
- public void removeListener(ExoplayerWrapper.PlaybackListener playbackListener)
playbackListener
- public void setInternalErrorListener(ExoplayerWrapper.InternalErrorListener listener)
listener
- The listener which responds to the error events.public void setInfoListener(ExoplayerWrapper.InfoListener listener)
listener
- Listens to media format changes, bandwidth samples, load events, and dropped
frames.public void setCaptionListener(ExoplayerWrapper.CaptionListener listener)
public void setTextListener(ExoplayerWrapper.TextListener listener)
listener
- The listener which can respond to text like subtitles and captions.public void setMetadataListener(ExoplayerWrapper.Id3MetadataListener listener)
public void setSurface(android.view.Surface surface)
public android.view.Surface getSurface()
public void blockingClearSurface()
In order to clear the surface, a message must be sent to the playback thread. To guarantee that this message is delivered, Exoplayer uses a blocking operation. Therefore, this method is blocking.
public java.lang.String[] getTracks(int type)
type
- The index indicating the type of video (ex TYPE_VIDEO
)public int getStateForTrackType(int type)
PRIMARY_TRACK
or {@link #DISABLED_TRACK).type
- The index indicating the type of video (ex TYPE_VIDEO
).public int getSelectedTrack(int type)
public void setSelectedTrack(int type, int index)
public boolean getBackgrounded()
public void setBackgrounded(boolean backgrounded)
public void prepare()
public void onRenderers(com.google.android.exoplayer.TrackRenderer[] renderers, com.google.android.exoplayer.upstream.BandwidthMeter bandwidthMeter)
ExoplayerWrapper.RendererBuilder
.renderers
- Renderers indexed by ExoplayerWrapper
TYPE_* constants. An
individual element may be null if there do not exist tracks of the
corresponding type.bandwidthMeter
- Provides an estimate of the currently available bandwidth. May be null.public void onRenderersError(java.lang.Exception e)
e
- The exception that has been thrown.public void setPlayWhenReady(boolean playWhenReady)
playWhenReady
- If true, playback will start as soon as the player is setup. If false, it
must be started programmatically.public void seekTo(int positionMs)
positionMs
- A number of milliseconds after the start of the video.public void release()
public int getPlaybackState()
public com.google.android.exoplayer.chunk.Format getFormat()
public com.google.android.exoplayer.upstream.BandwidthMeter getBandwidthMeter()
public com.google.android.exoplayer.CodecCounters getCodecCounters()
public long getCurrentPosition()
public long getDuration()
public int getBufferedPercentage()
public boolean getPlayWhenReady()
public void onPlayerStateChanged(boolean playWhenReady, int state)
onPlayerStateChanged
in interface com.google.android.exoplayer.ExoPlayer.Listener
public void onPlayerError(com.google.android.exoplayer.ExoPlaybackException exception)
onPlayerError
in interface com.google.android.exoplayer.ExoPlayer.Listener
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio)
onVideoSizeChanged
in interface com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListener
public void onDroppedFrames(int count, long elapsed)
onDroppedFrames
in interface com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListener
public void onBandwidthSample(int elapsedMs, long bytes, long bandwidthEstimate)
onBandwidthSample
in interface com.google.android.exoplayer.upstream.BandwidthMeter.EventListener
public void onDownstreamFormatChanged(int sourceId, com.google.android.exoplayer.chunk.Format format, int trigger, long mediaTimeMs)
onDownstreamFormatChanged
in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListener
public void onLoadStarted(int sourceId, long length, int type, int trigger, com.google.android.exoplayer.chunk.Format format, long mediaStartTimeMs, long mediaEndTimeMs)
onLoadStarted
in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListener
public void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, com.google.android.exoplayer.chunk.Format format, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs)
onLoadCompleted
in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListener
public void onLoadCanceled(int sourceId, long bytesLoaded)
onLoadCanceled
in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListener
public void onDrmSessionManagerError(java.lang.Exception e)
onDrmSessionManagerError
in interface com.google.android.exoplayer.drm.StreamingDrmSessionManager.EventListener
public void onDecoderInitializationError(com.google.android.exoplayer.MediaCodecTrackRenderer.DecoderInitializationException e)
onDecoderInitializationError
in interface com.google.android.exoplayer.MediaCodecTrackRenderer.EventListener
public void onAudioTrackInitializationError(com.google.android.exoplayer.audio.AudioTrack.InitializationException e)
onAudioTrackInitializationError
in interface com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListener
public void onAudioTrackWriteError(com.google.android.exoplayer.audio.AudioTrack.WriteException e)
onAudioTrackWriteError
in interface com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListener
public void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs)
onAudioTrackUnderrun
in interface com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListener
public void onCryptoError(android.media.MediaCodec.CryptoException e)
onCryptoError
in interface com.google.android.exoplayer.MediaCodecTrackRenderer.EventListener
public void onDrmKeysLoaded()
onDrmKeysLoaded
in interface com.google.android.exoplayer.drm.StreamingDrmSessionManager.EventListener
public void onDecoderInitialized(java.lang.String decoderName, long elapsedRealtimeMs, long initializationDurationMs)
onDecoderInitialized
in interface com.google.android.exoplayer.MediaCodecTrackRenderer.EventListener
public void onLoadError(int sourceId, java.io.IOException e)
onLoadError
in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListener
public void onCues(java.util.List<com.google.android.exoplayer.text.Cue> cues)
onCues
in interface com.google.android.exoplayer.text.TextRenderer
public void onMetadata(java.util.List<com.google.android.exoplayer.metadata.id3.Id3Frame> metadata)
onMetadata
in interface com.google.android.exoplayer.metadata.MetadataTrackRenderer.MetadataRenderer<java.util.List<com.google.android.exoplayer.metadata.id3.Id3Frame>>
public void onAvailableRangeChanged(int sourceId, com.google.android.exoplayer.TimeRange availableRange)
onAvailableRangeChanged
in interface com.google.android.exoplayer.dash.DashChunkSource.EventListener
public void onPlayWhenReadyCommitted()
onPlayWhenReadyCommitted
in interface com.google.android.exoplayer.ExoPlayer.Listener
public void onDrawnToSurface(android.view.Surface surface)
onDrawnToSurface
in interface com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListener
public void onUpstreamDiscarded(int sourceId, long mediaStartTimeMs, long mediaEndTimeMs)
onUpstreamDiscarded
in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListener