public class ExoMediaPlayer
extends java.lang.Object
implements com.google.android.exoplayer.ExoPlayer.Listener, com.google.android.exoplayer.chunk.ChunkSampleSource.EventListener, com.google.android.exoplayer.hls.HlsSampleSource.EventListener, com.google.android.exoplayer.extractor.ExtractorSampleSource.EventListener, com.google.android.exoplayer.SingleSampleSource.EventListener, com.google.android.exoplayer.upstream.BandwidthMeter.EventListener, com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListener, com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListener, com.google.android.exoplayer.drm.StreamingDrmSessionManager.EventListener, com.google.android.exoplayer.dash.DashChunkSource.EventListener, com.google.android.exoplayer.text.TextRenderer, com.google.android.exoplayer.metadata.MetadataTrackRenderer.MetadataRenderer<java.util.List<com.google.android.exoplayer.metadata.id3.Id3Frame>>, com.google.android.exoplayer.util.DebugTextViewHelper.Provider, com.google.android.exoplayer.audio.AudioCapabilitiesReceiver.Listener
ExoPlayer that provides a higher level interface. It can be prepared
with one of a number of ExoMediaPlayer.RendererBuilder classes to suit different use cases (e.g. DASH,
SmoothStreaming and so on).| Modifier and Type | Class and Description |
|---|---|
static interface |
ExoMediaPlayer.CaptionListener
A listener for receiving notifications of timed text.
|
static interface |
ExoMediaPlayer.Id3MetadataListener
A listener for receiving ID3 metadata parsed from the media stream.
|
static interface |
ExoMediaPlayer.InfoListener
A listener for debugging information.
|
static interface |
ExoMediaPlayer.InternalErrorListener
A listener for internal errors.
|
static interface |
ExoMediaPlayer.Listener
A listener for core events.
|
static interface |
ExoMediaPlayer.RendererBuilder
Builds renderers for the player.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
RENDERER_COUNT |
static int |
TRACK_DEFAULT |
static int |
TRACK_DISABLED |
static int |
TYPE_AUDIO |
static int |
TYPE_METADATA |
static int |
TYPE_TEXT |
static int |
TYPE_VIDEO |
| Constructor and Description |
|---|
ExoMediaPlayer(ExoMediaPlayer.RendererBuilder rendererBuilder) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(ExoMediaPlayer.Listener listener) |
void |
blockingClearSurface() |
int |
getAudioSessionId() |
boolean |
getBackgrounded() |
com.google.android.exoplayer.upstream.BandwidthMeter |
getBandwidthMeter()
Returns a
BandwidthMeter whose estimate should be displayed, or null. |
int |
getBufferedPercentage() |
com.google.android.exoplayer.CodecCounters |
getCodecCounters()
Returns a
CodecCounters whose information should be displayed, or null. |
long |
getCurrentPosition()
Returns the current playback position, in milliseconds.
|
long |
getDuration() |
com.google.android.exoplayer.chunk.Format |
getFormat()
Returns a format whose information should be displayed, or null.
|
int |
getPlaybackState() |
boolean |
getPlayWhenReady() |
int |
getSelectedTrack(int type) |
android.view.Surface |
getSurface() |
int |
getTrackCount(int type) |
com.google.android.exoplayer.MediaFormat |
getTrackFormat(int type,
int index) |
int |
getVideoHeight() |
int |
getVideoWidth() |
boolean |
isPlaying() |
void |
onAudioCapabilitiesChanged(com.google.android.exoplayer.audio.AudioCapabilities audioCapabilities)
Called when the audio capabilities change.
|
void |
onAudioTrackInitializationError(com.google.android.exoplayer.audio.AudioTrack.InitializationException e)
Invoked when an
AudioTrack fails to initialize. |
void |
onAudioTrackUnderrun(int bufferSize,
long bufferSizeMs,
long elapsedSinceLastFeedMs)
Invoked when an
AudioTrack underrun occurs. |
void |
onAudioTrackWriteError(com.google.android.exoplayer.audio.AudioTrack.WriteException e)
Invoked when an
AudioTrack write fails. |
void |
onAvailableRangeChanged(int sourceId,
com.google.android.exoplayer.TimeRange availableRange)
Invoked when the available seek range of the stream has changed.
|
void |
onBandwidthSample(int elapsedMs,
long bytes,
long bitrateEstimate)
Invoked periodically to indicate that bytes have been transferred.
|
void |
onCryptoError(android.media.MediaCodec.CryptoException e)
Invoked when a decoder operation raises a
MediaCodec.CryptoException. |
void |
onCues(java.util.List<com.google.android.exoplayer.text.Cue> cues)
Invoked each time there is a change in the
Cues to be rendered. |
void |
onDecoderInitializationError(com.google.android.exoplayer.MediaCodecTrackRenderer.DecoderInitializationException e)
Invoked when a decoder fails to initialize.
|
void |
onDecoderInitialized(java.lang.String decoderName,
long elapsedRealtimeMs,
long initializationDurationMs)
Invoked when a decoder is successfully created.
|
void |
onDownstreamFormatChanged(int sourceId,
com.google.android.exoplayer.chunk.Format format,
int trigger,
long mediaTimeMs)
Invoked when the downstream format changes (i.e.
|
void |
onDrawnToSurface(android.view.Surface surface)
Invoked when a frame is rendered to a surface for the first time following that surface
having been set as the target for the renderer.
|
void |
onDrmKeysLoaded()
Invoked each time keys are loaded.
|
void |
onDrmSessionManagerError(java.lang.Exception e)
Invoked when a drm error occurs.
|
void |
onDroppedFrames(int count,
long elapsed)
Invoked to report the number of frames dropped by the renderer.
|
void |
onLoadCanceled(int sourceId,
long bytesLoaded)
Invoked when the current upstream load operation is canceled.
|
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)
Invoked when the current load operation completes.
|
void |
onLoadError(int sourceId,
java.io.IOException e)
Invoked when an error occurs loading media data.
|
void |
onLoadStarted(int sourceId,
long length,
int type,
int trigger,
com.google.android.exoplayer.chunk.Format format,
long mediaStartTimeMs,
long mediaEndTimeMs)
Invoked when an upstream load is started.
|
void |
onMetadata(java.util.List<com.google.android.exoplayer.metadata.id3.Id3Frame> id3Frames)
Invoked each time there is a metadata associated with current playback time.
|
void |
onPlayerError(com.google.android.exoplayer.ExoPlaybackException exception)
Invoked when an error occurs.
|
void |
onPlayerStateChanged(boolean playWhenReady,
int state)
Invoked when the value returned from either
ExoPlayer.getPlayWhenReady() or
ExoPlayer.getPlaybackState() changes. |
void |
onPlayWhenReadyCommitted()
Invoked when the current value of
ExoPlayer.getPlayWhenReady() has been reflected
by the internal playback thread. |
void |
onUpstreamDiscarded(int sourceId,
long mediaStartTimeMs,
long mediaEndTimeMs)
Invoked when data is removed from the back of the buffer, typically so that it can be
re-buffered using a different representation.
|
void |
onVideoSizeChanged(int width,
int height,
int unAppliedRotationDegrees,
float pixelWidthHeightRatio)
Invoked each time there's a change in the size of the video being rendered.
|
void |
pause() |
void |
prepare() |
void |
prepareAsync() |
void |
release() |
void |
removeListener(ExoMediaPlayer.Listener listener) |
void |
reset() |
void |
seekTo(long positionMs) |
void |
setAudioSessionId(int audioSessionId) |
void |
setAudioStreamType(int audioStreamType) |
void |
setBackgrounded(boolean backgrounded) |
void |
setCaptionListener(ExoMediaPlayer.CaptionListener listener) |
void |
setDataSource(android.content.Context context,
android.net.Uri uri,
java.util.Map<java.lang.String,java.lang.String> headers) |
void |
setInfoListener(ExoMediaPlayer.InfoListener listener) |
void |
setInternalErrorListener(ExoMediaPlayer.InternalErrorListener listener) |
void |
setMetadataListener(ExoMediaPlayer.Id3MetadataListener listener) |
void |
setOnInfoListener(OnInfoListener listener) |
void |
setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener) |
void |
setPlayerStateChangeListener(OnPlayerStateChangeListener listener) |
void |
setPlayWhenReady(boolean playWhenReady) |
void |
setScreenOnWhilePlaying(boolean screenOnWhilePlaying) |
void |
setSelectedTrack(int type,
int index) |
void |
setSurface(android.view.Surface surface) |
void |
setVolume(float volume) |
void |
start() |
void |
stop() |
public static final int TRACK_DISABLED
public static final int TRACK_DEFAULT
public static final int RENDERER_COUNT
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 ExoMediaPlayer(ExoMediaPlayer.RendererBuilder rendererBuilder)
public void onAudioCapabilitiesChanged(com.google.android.exoplayer.audio.AudioCapabilities audioCapabilities)
com.google.android.exoplayer.audio.AudioCapabilitiesReceiver.ListeneronAudioCapabilitiesChanged in interface com.google.android.exoplayer.audio.AudioCapabilitiesReceiver.ListeneraudioCapabilities - Current audio capabilities for the device.public void addListener(ExoMediaPlayer.Listener listener)
public void removeListener(ExoMediaPlayer.Listener listener)
public void setInternalErrorListener(ExoMediaPlayer.InternalErrorListener listener)
public void setInfoListener(ExoMediaPlayer.InfoListener listener)
public void setCaptionListener(ExoMediaPlayer.CaptionListener listener)
public void setMetadataListener(ExoMediaPlayer.Id3MetadataListener listener)
public void setSurface(android.view.Surface surface)
public void prepareAsync()
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionpublic android.view.Surface getSurface()
public void blockingClearSurface()
public int getTrackCount(int type)
public com.google.android.exoplayer.MediaFormat getTrackFormat(int type,
int index)
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 setPlayWhenReady(boolean playWhenReady)
public void seekTo(long positionMs)
public boolean isPlaying()
public int getVideoWidth()
public int getVideoHeight()
public void setPlayerStateChangeListener(OnPlayerStateChangeListener listener)
public void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener)
public void start()
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionpublic void pause()
public void stop()
public void release()
public void reset()
public int getPlaybackState()
public com.google.android.exoplayer.chunk.Format getFormat()
com.google.android.exoplayer.util.DebugTextViewHelper.ProvidergetFormat in interface com.google.android.exoplayer.util.DebugTextViewHelper.Providerpublic com.google.android.exoplayer.upstream.BandwidthMeter getBandwidthMeter()
com.google.android.exoplayer.util.DebugTextViewHelper.ProviderBandwidthMeter whose estimate should be displayed, or null.getBandwidthMeter in interface com.google.android.exoplayer.util.DebugTextViewHelper.Providerpublic com.google.android.exoplayer.CodecCounters getCodecCounters()
com.google.android.exoplayer.util.DebugTextViewHelper.ProviderCodecCounters whose information should be displayed, or null.getCodecCounters in interface com.google.android.exoplayer.util.DebugTextViewHelper.Providerpublic long getCurrentPosition()
com.google.android.exoplayer.util.DebugTextViewHelper.ProvidergetCurrentPosition in interface com.google.android.exoplayer.util.DebugTextViewHelper.Providerpublic long getDuration()
public int getBufferedPercentage()
public boolean getPlayWhenReady()
public void onPlayerStateChanged(boolean playWhenReady,
int state)
com.google.android.exoplayer.ExoPlayer.ListenerExoPlayer.getPlayWhenReady() or
ExoPlayer.getPlaybackState() changes.onPlayerStateChanged in interface com.google.android.exoplayer.ExoPlayer.ListenerplayWhenReady - Whether playback will proceed when ready.state - One of the STATE constants defined in the ExoPlayer
interface.public void onPlayerError(com.google.android.exoplayer.ExoPlaybackException exception)
com.google.android.exoplayer.ExoPlayer.ListenerExoPlayer.STATE_IDLE immediately after this method is invoked. The player instance
can still be used, and ExoPlayer.release() must still be called on the player should
it no longer be required.onPlayerError in interface com.google.android.exoplayer.ExoPlayer.Listenerexception - The error.public void onVideoSizeChanged(int width,
int height,
int unAppliedRotationDegrees,
float pixelWidthHeightRatio)
com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListeneronVideoSizeChanged in interface com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListenerwidth - The video width in pixels.height - The video height in pixels.unAppliedRotationDegrees - For videos that require a rotation, this is the clockwise
rotation in degrees that the application should apply for the video for it to be rendered
in the correct orientation. This value will always be zero on API levels 21 and above,
since the renderer will apply all necessary rotations internally. On earlier API levels
this is not possible. Applications that use TextureView can apply the rotation by
calling TextureView.setTransform(android.graphics.Matrix). Applications that do not expect to encounter
rotated videos can safely ignore this parameter.pixelWidthHeightRatio - The width to height ratio of each pixel. For the normal case
of square pixels this will be equal to 1.0. Different values are indicative of anamorphic
content.public void onDroppedFrames(int count,
long elapsed)
com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListeneronDroppedFrames in interface com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListenercount - The number of dropped frames.elapsed - The duration in milliseconds over which the frames were dropped. This
duration is timed from when the renderer was started or from when dropped frames were
last reported (whichever was more recent), and not from when the first of the reported
drops occurred.public void onBandwidthSample(int elapsedMs,
long bytes,
long bitrateEstimate)
com.google.android.exoplayer.upstream.BandwidthMeter.EventListeneronBandwidthSample in interface com.google.android.exoplayer.upstream.BandwidthMeter.EventListenerelapsedMs - The time taken to transfer the bytes, in milliseconds.bytes - The number of bytes transferred.bitrateEstimate - The estimated bitrate in bits/sec, or BandwidthMeter.NO_ESTIMATE if no estimate
is available. Note that this estimate is typically derived from more information than
bytes and elapsedMs.public void onDownstreamFormatChanged(int sourceId,
com.google.android.exoplayer.chunk.Format format,
int trigger,
long mediaTimeMs)
com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListenerSampleSource.SampleSourceReader.readData(int, long, com.google.android.exoplayer.MediaFormatHolder, com.google.android.exoplayer.SampleHolder) changes).onDownstreamFormatChanged in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListenersourceId - The id of the reporting SampleSource.format - The format.trigger - The trigger specified in the corresponding upstream load, as specified by the
ChunkSource.mediaTimeMs - The media time at which the change occurred.public void onDrmKeysLoaded()
com.google.android.exoplayer.drm.StreamingDrmSessionManager.EventListeneronDrmKeysLoaded in interface com.google.android.exoplayer.drm.StreamingDrmSessionManager.EventListenerpublic void onDrmSessionManagerError(java.lang.Exception e)
com.google.android.exoplayer.drm.StreamingDrmSessionManager.EventListeneronDrmSessionManagerError in interface com.google.android.exoplayer.drm.StreamingDrmSessionManager.EventListenere - The corresponding exception.public void onDecoderInitializationError(com.google.android.exoplayer.MediaCodecTrackRenderer.DecoderInitializationException e)
com.google.android.exoplayer.MediaCodecTrackRenderer.EventListeneronDecoderInitializationError in interface com.google.android.exoplayer.MediaCodecTrackRenderer.EventListenere - The corresponding exception.public void onAudioTrackInitializationError(com.google.android.exoplayer.audio.AudioTrack.InitializationException e)
com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListenerAudioTrack fails to initialize.onAudioTrackInitializationError in interface com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListenere - The corresponding exception.public void onAudioTrackWriteError(com.google.android.exoplayer.audio.AudioTrack.WriteException e)
com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListenerAudioTrack write fails.onAudioTrackWriteError in interface com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListenere - The corresponding exception.public void onAudioTrackUnderrun(int bufferSize,
long bufferSizeMs,
long elapsedSinceLastFeedMs)
com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListenerAudioTrack underrun occurs.onAudioTrackUnderrun in interface com.google.android.exoplayer.MediaCodecAudioTrackRenderer.EventListenerbufferSize - The size of the AudioTrack's buffer, in bytes.bufferSizeMs - The size of the AudioTrack's buffer, in milliseconds, if it is
configured for PCM output. -1 if it is configured for passthrough output, as the buffered
media can have a variable bitrate so the duration may be unknown.elapsedSinceLastFeedMs - The time since the AudioTrack was last fed data.public void onCryptoError(android.media.MediaCodec.CryptoException e)
com.google.android.exoplayer.MediaCodecTrackRenderer.EventListenerMediaCodec.CryptoException.onCryptoError in interface com.google.android.exoplayer.MediaCodecTrackRenderer.EventListenere - The corresponding exception.public void onDecoderInitialized(java.lang.String decoderName,
long elapsedRealtimeMs,
long initializationDurationMs)
com.google.android.exoplayer.MediaCodecTrackRenderer.EventListeneronDecoderInitialized in interface com.google.android.exoplayer.MediaCodecTrackRenderer.EventListenerdecoderName - The decoder that was configured and created.elapsedRealtimeMs - elapsedRealtime timestamp of when the initialization
finished.initializationDurationMs - Amount of time taken to initialize the decoder.public void onLoadError(int sourceId,
java.io.IOException e)
com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListeneronLoadError in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListeneronLoadError in interface com.google.android.exoplayer.extractor.ExtractorSampleSource.EventListeneronLoadError in interface com.google.android.exoplayer.SingleSampleSource.EventListenersourceId - The id of the reporting SampleSource.e - The cause of the failure.public void onCues(java.util.List<com.google.android.exoplayer.text.Cue> cues)
com.google.android.exoplayer.text.TextRendererCues to be rendered.onCues in interface com.google.android.exoplayer.text.TextRenderercues - The Cues to be rendered, or an empty list if no cues are to be rendered.public void onMetadata(java.util.List<com.google.android.exoplayer.metadata.id3.Id3Frame> id3Frames)
com.google.android.exoplayer.metadata.MetadataTrackRenderer.MetadataRendereronMetadata in interface com.google.android.exoplayer.metadata.MetadataTrackRenderer.MetadataRenderer<java.util.List<com.google.android.exoplayer.metadata.id3.Id3Frame>>id3Frames - The metadata to process.public void onAvailableRangeChanged(int sourceId,
com.google.android.exoplayer.TimeRange availableRange)
com.google.android.exoplayer.dash.DashChunkSource.EventListeneronAvailableRangeChanged in interface com.google.android.exoplayer.dash.DashChunkSource.EventListenersourceId - The id of the reporting DashChunkSource.availableRange - The range which specifies available content that can be seeked to.public void onPlayWhenReadyCommitted()
com.google.android.exoplayer.ExoPlayer.ListenerExoPlayer.getPlayWhenReady() has been reflected
by the internal playback thread.
An invocation of this method will shortly follow any call to
ExoPlayer.setPlayWhenReady(boolean) that changes the state. If multiple calls are
made in rapid succession, then this method will be invoked only once, after the final state
has been reflected.
onPlayWhenReadyCommitted in interface com.google.android.exoplayer.ExoPlayer.Listenerpublic void onDrawnToSurface(android.view.Surface surface)
com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListeneronDrawnToSurface in interface com.google.android.exoplayer.MediaCodecVideoTrackRenderer.EventListenersurface - The surface to which a first frame has been rendered.public void onLoadStarted(int sourceId,
long length,
int type,
int trigger,
com.google.android.exoplayer.chunk.Format format,
long mediaStartTimeMs,
long mediaEndTimeMs)
com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListeneronLoadStarted in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListenersourceId - The id of the reporting SampleSource.length - The length of the data being loaded in bytes, or C.LENGTH_UNBOUNDED if
the length of the data is not known in advance.type - The type of the data being loaded.trigger - The reason for the data being loaded.format - The particular format to which this data corresponds, or null if the data being
loaded does not correspond to a format.mediaStartTimeMs - The media time of the start of the data being loaded, or -1 if this
load is for initialization data.mediaEndTimeMs - The media time of the end of the data being loaded, or -1 if this
load is for initialization data.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)
com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListeneronLoadCompleted in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListenersourceId - The id of the reporting SampleSource.bytesLoaded - The number of bytes that were loaded.type - The type of the loaded data.trigger - The reason for the data being loaded.format - The particular format to which this data corresponds, or null if the loaded data
does not correspond to a format.mediaStartTimeMs - The media time of the start of the loaded data, or -1 if this load was
for initialization data.mediaEndTimeMs - The media time of the end of the loaded data, or -1 if this load was for
initialization data.elapsedRealtimeMs - elapsedRealtime timestamp of when the load finished.loadDurationMs - Amount of time taken to load the data.public void onLoadCanceled(int sourceId,
long bytesLoaded)
com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListeneronLoadCanceled in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListenersourceId - The id of the reporting SampleSource.bytesLoaded - The number of bytes that were loaded prior to the cancellation.public void onUpstreamDiscarded(int sourceId,
long mediaStartTimeMs,
long mediaEndTimeMs)
com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListeneronUpstreamDiscarded in interface com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListenersourceId - The id of the reporting SampleSource.mediaStartTimeMs - The media time of the start of the discarded data.mediaEndTimeMs - The media time of the end of the discarded data.public void setVolume(float volume)
public void setAudioSessionId(int audioSessionId)
public int getAudioSessionId()
public void setOnInfoListener(OnInfoListener listener)
public void setDataSource(android.content.Context context,
android.net.Uri uri,
java.util.Map<java.lang.String,java.lang.String> headers)
throws java.io.IOException,
java.lang.IllegalArgumentException,
java.lang.SecurityException,
java.lang.IllegalStateException
java.io.IOExceptionjava.lang.IllegalArgumentExceptionjava.lang.SecurityExceptionjava.lang.IllegalStateExceptionpublic void setAudioStreamType(int audioStreamType)
public void setScreenOnWhilePlaying(boolean screenOnWhilePlaying)