ExoPlayer
, Player
, Player.AudioComponent
, Player.DeviceComponent
, Player.MetadataComponent
, Player.TextComponent
, Player.VideoComponent
public class SimpleExoPlayer extends BasePlayer implements ExoPlayer, Player.AudioComponent, Player.VideoComponent, Player.TextComponent, Player.MetadataComponent, Player.DeviceComponent
ExoPlayer
implementation that uses default Renderer
components. Instances can
be obtained from SimpleExoPlayer.Builder
.Modifier and Type | Class | Description |
---|---|---|
static class |
SimpleExoPlayer.Builder |
A builder for
SimpleExoPlayer instances. |
Player.AudioComponent, Player.DefaultEventListener, Player.DeviceComponent, Player.DiscontinuityReason, Player.EventFlags, Player.EventListener, Player.Events, Player.MediaItemTransitionReason, Player.MetadataComponent, Player.PlaybackSuppressionReason, Player.PlayWhenReadyChangeReason, Player.RepeatMode, Player.State, Player.TextComponent, Player.TimelineChangeReason, Player.VideoComponent
Modifier and Type | Field | Description |
---|---|---|
static long |
DEFAULT_DETACH_SURFACE_TIMEOUT_MS |
The default timeout for detaching a surface from the player, in milliseconds.
|
protected Renderer[] |
renderers |
window
DEFAULT_RELEASE_TIMEOUT_MS
DISCONTINUITY_REASON_AD_INSERTION, DISCONTINUITY_REASON_INTERNAL, DISCONTINUITY_REASON_PERIOD_TRANSITION, DISCONTINUITY_REASON_SEEK, DISCONTINUITY_REASON_SEEK_ADJUSTMENT, EVENT_IS_LOADING_CHANGED, EVENT_IS_PLAYING_CHANGED, EVENT_MEDIA_ITEM_TRANSITION, EVENT_PLAY_WHEN_READY_CHANGED, EVENT_PLAYBACK_PARAMETERS_CHANGED, EVENT_PLAYBACK_STATE_CHANGED, EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED, EVENT_PLAYER_ERROR, EVENT_POSITION_DISCONTINUITY, EVENT_REPEAT_MODE_CHANGED, EVENT_SHUFFLE_MODE_ENABLED_CHANGED, EVENT_STATIC_METADATA_CHANGED, EVENT_TIMELINE_CHANGED, EVENT_TRACKS_CHANGED, MEDIA_ITEM_TRANSITION_REASON_AUTO, MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED, MEDIA_ITEM_TRANSITION_REASON_REPEAT, MEDIA_ITEM_TRANSITION_REASON_SEEK, PLAY_WHEN_READY_CHANGE_REASON_AUDIO_BECOMING_NOISY, PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS, PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM, PLAY_WHEN_READY_CHANGE_REASON_REMOTE, PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST, PLAYBACK_SUPPRESSION_REASON_NONE, PLAYBACK_SUPPRESSION_REASON_TRANSIENT_AUDIO_FOCUS_LOSS, REPEAT_MODE_ALL, REPEAT_MODE_OFF, REPEAT_MODE_ONE, STATE_BUFFERING, STATE_ENDED, STATE_IDLE, STATE_READY, TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED, TIMELINE_CHANGE_REASON_SOURCE_UPDATE
Modifier | Constructor | Description |
---|---|---|
protected |
SimpleExoPlayer(Context context,
RenderersFactory renderersFactory,
TrackSelector trackSelector,
MediaSourceFactory mediaSourceFactory,
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
AnalyticsCollector analyticsCollector,
boolean useLazyPreparation,
Clock clock,
Looper applicationLooper) |
Deprecated.
Use the
SimpleExoPlayer.Builder and pass it to SimpleExoPlayer(Builder) . |
protected |
SimpleExoPlayer(SimpleExoPlayer.Builder builder) |
Modifier and Type | Method | Description |
---|---|---|
void |
addAnalyticsListener(AnalyticsListener listener) |
Adds an
AnalyticsListener to receive analytics events. |
void |
addAudioListener(AudioListener listener) |
Adds a listener to receive audio events.
|
void |
addDeviceListener(DeviceListener listener) |
Adds a listener to receive device events.
|
void |
addListener(Player.EventListener listener) |
Register a listener to receive events from the player.
|
void |
addMediaItem(int index,
MediaItem mediaItem) |
Adds a media item at the given index of the playlist.
|
void |
addMediaItem(MediaItem mediaItem) |
Adds a media item to the end of the playlist.
|
void |
addMediaItems(int index,
List<MediaItem> mediaItems) |
Adds a list of media items at the given index of the playlist.
|
void |
addMediaItems(List<MediaItem> mediaItems) |
Adds a list of media items to the end of the playlist.
|
void |
addMediaSource(int index,
MediaSource mediaSource) |
Adds a media source at the given index of the playlist.
|
void |
addMediaSource(MediaSource mediaSource) |
Adds a media source to the end of the playlist.
|
void |
addMediaSources(int index,
List<MediaSource> mediaSources) |
Adds a list of media sources at the given index of the playlist.
|
void |
addMediaSources(List<MediaSource> mediaSources) |
Adds a list of media sources to the end of the playlist.
|
void |
addMetadataOutput(MetadataOutput listener) |
Adds a
MetadataOutput to receive metadata. |
void |
addTextOutput(TextOutput listener) |
Registers an output to receive text events.
|
void |
addVideoListener(VideoListener listener) |
Adds a listener to receive video events.
|
void |
clearAuxEffectInfo() |
Detaches any previously attached auxiliary audio effect from the underlying audio track.
|
void |
clearCameraMotionListener(CameraMotionListener listener) |
Clears the listener which receives camera motion events if it matches the one passed.
|
void |
clearMediaItems() |
Clears the playlist.
|
void |
clearVideoFrameMetadataListener(VideoFrameMetadataListener listener) |
Clears the listener which receives video frame metadata events if it matches the one passed.
|
void |
clearVideoSurface() |
|
void |
clearVideoSurface(Surface surface) |
Clears the
Surface onto which video is being rendered if it matches the one passed. |
void |
clearVideoSurfaceHolder(SurfaceHolder surfaceHolder) |
Clears the
SurfaceHolder that holds the Surface onto which video is being
rendered if it matches the one passed. |
void |
clearVideoSurfaceView(SurfaceView surfaceView) |
Clears the
SurfaceView onto which video is being rendered if it matches the one
passed. |
void |
clearVideoTextureView(TextureView textureView) |
Clears the
TextureView onto which video is being rendered if it matches the one
passed. |
PlayerMessage |
createMessage(PlayerMessage.Target target) |
Creates a message that can be sent to a
PlayerMessage.Target . |
void |
decreaseDeviceVolume() |
Decreases the volume of the device.
|
boolean |
experimentalIsSleepingForOffload() |
Returns whether the player has paused its main loop to save power in offload scheduling mode.
|
void |
experimentalSetOffloadSchedulingEnabled(boolean offloadSchedulingEnabled) |
Sets whether audio offload scheduling is enabled.
|
AnalyticsCollector |
getAnalyticsCollector() |
Returns the
AnalyticsCollector used for collecting analytics events. |
Looper |
getApplicationLooper() |
Returns the
Looper associated with the application thread that's used to access the
player and on which player events are received. |
AudioAttributes |
getAudioAttributes() |
Returns the attributes for audio playback.
|
Player.AudioComponent |
getAudioComponent() |
Returns the component of this player for audio output, or null if audio is not supported.
|
DecoderCounters |
getAudioDecoderCounters() |
Returns
DecoderCounters for audio, or null if no audio is being played. |
Format |
getAudioFormat() |
Returns the audio format currently being played, or null if no audio is being played.
|
int |
getAudioSessionId() |
Returns the audio session identifier, or
C.AUDIO_SESSION_ID_UNSET if not set. |
long |
getBufferedPosition() |
Returns an estimate of the position in the current content window or ad up to which data is
buffered, in milliseconds.
|
Clock |
getClock() |
Returns the
Clock used for playback. |
long |
getContentBufferedPosition() |
If
Player.isPlayingAd() returns true , returns an estimate of the content position in
the current content window up to which data is buffered, in milliseconds. |
long |
getContentPosition() |
If
Player.isPlayingAd() returns true , returns the content position that will be
played once all ads in the ad group have finished playing, in milliseconds. |
int |
getCurrentAdGroupIndex() |
If
Player.isPlayingAd() returns true, returns the index of the ad group in the period
currently being played. |
int |
getCurrentAdIndexInAdGroup() |
If
Player.isPlayingAd() returns true, returns the index of the ad in its ad group. |
List<Cue> |
getCurrentCues() |
Returns the current
Cues . |
int |
getCurrentPeriodIndex() |
Returns the index of the period currently being played.
|
long |
getCurrentPosition() |
Returns the playback position in the current content window or ad, in milliseconds, or the
prospective position in milliseconds if the
current timeline is
empty. |
List<Metadata> |
getCurrentStaticMetadata() |
Returns the current static metadata for the track selections.
|
Timeline |
getCurrentTimeline() |
Returns the current
Timeline . |
TrackGroupArray |
getCurrentTrackGroups() |
Returns the available track groups.
|
TrackSelectionArray |
getCurrentTrackSelections() |
Returns the current track selections for each renderer.
|
int |
getCurrentWindowIndex() |
Returns the index of the current
window in the timeline , or the prospective window index if the current timeline is empty. |
Player.DeviceComponent |
getDeviceComponent() |
Returns the component of this player for playback device, or null if it's not supported.
|
DeviceInfo |
getDeviceInfo() |
Gets the device information.
|
int |
getDeviceVolume() |
Gets the current volume of the device.
|
long |
getDuration() |
Returns the duration of the current content window or ad in milliseconds, or
C.TIME_UNSET if the duration is not known. |
Player.MetadataComponent |
getMetadataComponent() |
Returns the component of this player for metadata output, or null if metadata is not supported.
|
boolean |
getPauseAtEndOfMediaItems() |
Returns whether the player pauses playback at the end of each media item.
|
ExoPlaybackException |
getPlaybackError() |
Deprecated.
Use
getPlayerError() instead. |
Looper |
getPlaybackLooper() |
Returns the
Looper associated with the playback thread. |
PlaybackParameters |
getPlaybackParameters() |
Returns the currently active playback parameters.
|
int |
getPlaybackState() |
Returns the current
playback state of the player. |
int |
getPlaybackSuppressionReason() |
Returns the reason why playback is suppressed even though
Player.getPlayWhenReady() is
true , or Player.PLAYBACK_SUPPRESSION_REASON_NONE if playback is not suppressed. |
ExoPlaybackException |
getPlayerError() |
Returns the error that caused playback to fail.
|
boolean |
getPlayWhenReady() |
Whether playback will proceed when
Player.getPlaybackState() == Player.STATE_READY . |
int |
getRendererCount() |
Returns the number of renderers.
|
int |
getRendererType(int index) |
Returns the track type that the renderer at a given index handles.
|
int |
getRepeatMode() |
Returns the current
Player.RepeatMode used for playback. |
SeekParameters |
getSeekParameters() |
Returns the currently active
SeekParameters of the player. |
boolean |
getShuffleModeEnabled() |
Returns whether shuffling of windows is enabled.
|
boolean |
getSkipSilenceEnabled() |
Returns whether skipping silences in the audio stream is enabled.
|
Player.TextComponent |
getTextComponent() |
Returns the component of this player for text output, or null if text is not supported.
|
long |
getTotalBufferedDuration() |
Returns an estimate of the total buffered duration from the current position, in milliseconds.
|
TrackSelector |
getTrackSelector() |
Returns the track selector that this player uses, or null if track selection is not supported.
|
Player.VideoComponent |
getVideoComponent() |
Returns the component of this player for video output, or null if video is not supported.
|
DecoderCounters |
getVideoDecoderCounters() |
Returns
DecoderCounters for video, or null if no video is being played. |
Format |
getVideoFormat() |
Returns the video format currently being played, or null if no video is being played.
|
int |
getVideoScalingMode() |
Returns the
C.VideoScalingMode . |
float |
getVolume() |
Returns the audio volume, with 0 being silence and 1 being unity gain.
|
void |
increaseDeviceVolume() |
Increases the volume of the device.
|
boolean |
isDeviceMuted() |
Gets whether the device is muted or not.
|
boolean |
isLoading() |
Whether the player is currently loading the source.
|
boolean |
isPlayingAd() |
Returns whether the player is currently playing an ad.
|
void |
moveMediaItem(int currentIndex,
int newIndex) |
Moves the media item at the current index to the new index.
|
void |
moveMediaItems(int fromIndex,
int toIndex,
int newIndex) |
Moves the media item range to the new index.
|
void |
prepare() |
Prepares the player.
|
void |
prepare(MediaSource mediaSource) |
Deprecated.
Use
setMediaSource(MediaSource) and Player.prepare() instead. |
void |
prepare(MediaSource mediaSource,
boolean resetPosition,
boolean resetState) |
Deprecated.
Use
setMediaSource(MediaSource, boolean) and Player.prepare()
instead. |
void |
release() |
Releases the player.
|
void |
removeAnalyticsListener(AnalyticsListener listener) |
Removes an
AnalyticsListener . |
void |
removeAudioListener(AudioListener listener) |
Removes a listener of audio events.
|
void |
removeDeviceListener(DeviceListener listener) |
Removes a listener of device events.
|
void |
removeListener(Player.EventListener listener) |
Unregister a listener.
|
void |
removeMediaItem(int index) |
Removes the media item at the given index of the playlist.
|
void |
removeMediaItems(int fromIndex,
int toIndex) |
Removes a range of media items from the playlist.
|
void |
removeMetadataOutput(MetadataOutput listener) |
Removes a
MetadataOutput . |
void |
removeTextOutput(TextOutput listener) |
Removes a text output.
|
void |
removeVideoListener(VideoListener listener) |
Removes a listener of video events.
|
void |
retry() |
Deprecated.
Use
prepare() instead. |
void |
seekTo(int windowIndex,
long positionMs) |
Seeks to a position specified in milliseconds in the specified window.
|
void |
setAudioAttributes(AudioAttributes audioAttributes,
boolean handleAudioFocus) |
Sets the attributes for audio playback, used by the underlying audio track.
|
void |
setAudioSessionId(int audioSessionId) |
Sets the ID of the audio session to attach to the underlying
AudioTrack . |
void |
setAuxEffectInfo(AuxEffectInfo auxEffectInfo) |
Sets information on an auxiliary audio effect to attach to the underlying audio track.
|
void |
setCameraMotionListener(CameraMotionListener listener) |
Sets a listener of camera motion events.
|
void |
setDeviceMuted(boolean muted) |
Sets the mute state of the device.
|
void |
setDeviceVolume(int volume) |
Sets the volume of the device.
|
void |
setForegroundMode(boolean foregroundMode) |
Sets whether the player is allowed to keep holding limited resources such as video decoders,
even when in the idle state.
|
void |
setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) |
Sets whether the player should pause automatically when audio is rerouted from a headset to
device speakers.
|
void |
setHandleWakeLock(boolean handleWakeLock) |
Deprecated.
Use
setWakeMode(int) instead. |
void |
setMediaItem(MediaItem mediaItem) |
Clears the playlist, adds the specified
MediaItem and resets the position to the
default position. |
void |
setMediaItem(MediaItem mediaItem,
boolean resetPosition) |
Clears the playlist and adds the specified
MediaItem . |
void |
setMediaItem(MediaItem mediaItem,
long startPositionMs) |
Clears the playlist and adds the specified
MediaItem . |
void |
setMediaItems(List<MediaItem> mediaItems) |
Clears the playlist, adds the specified
MediaItems and resets the position to
the default position. |
void |
setMediaItems(List<MediaItem> mediaItems,
boolean resetPosition) |
Clears the playlist and adds the specified
MediaItems . |
void |
setMediaItems(List<MediaItem> mediaItems,
int startWindowIndex,
long startPositionMs) |
Clears the playlist and adds the specified
MediaItems . |
void |
setMediaSource(MediaSource mediaSource) |
Clears the playlist, adds the specified
MediaSource and resets the position to the
default position. |
void |
setMediaSource(MediaSource mediaSource,
boolean resetPosition) |
Clears the playlist and adds the specified
MediaSource . |
void |
setMediaSource(MediaSource mediaSource,
long startPositionMs) |
Clears the playlist and adds the specified
MediaSource . |
void |
setMediaSources(List<MediaSource> mediaSources) |
Clears the playlist, adds the specified
MediaSources and resets the
position to the default position. |
void |
setMediaSources(List<MediaSource> mediaSources,
boolean resetPosition) |
Clears the playlist and adds the specified
MediaSources . |
void |
setMediaSources(List<MediaSource> mediaSources,
int startWindowIndex,
long startPositionMs) |
Clears the playlist and adds the specified
MediaSources . |
void |
setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems) |
Sets whether to pause playback at the end of each media item.
|
void |
setPlaybackParameters(PlaybackParameters playbackParameters) |
Attempts to set the playback parameters.
|
void |
setPlayWhenReady(boolean playWhenReady) |
Sets whether playback should proceed when
Player.getPlaybackState() == Player.STATE_READY . |
void |
setPriorityTaskManager(PriorityTaskManager priorityTaskManager) |
Sets a
PriorityTaskManager , or null to clear a previously set priority task manager. |
void |
setRepeatMode(int repeatMode) |
Sets the
Player.RepeatMode to be used for playback. |
void |
setSeekParameters(SeekParameters seekParameters) |
Sets the parameters that control how seek operations are performed.
|
void |
setShuffleModeEnabled(boolean shuffleModeEnabled) |
Sets whether shuffling of windows is enabled.
|
void |
setShuffleOrder(ShuffleOrder shuffleOrder) |
Sets the shuffle order.
|
void |
setSkipSilenceEnabled(boolean skipSilenceEnabled) |
Sets whether skipping silences in the audio stream is enabled.
|
void |
setThrowsWhenUsingWrongThread(boolean throwsWhenUsingWrongThread) |
Sets whether the player should throw an
IllegalStateException when methods are called
from a thread other than the one associated with getApplicationLooper() . |
void |
setVideoFrameMetadataListener(VideoFrameMetadataListener listener) |
Sets a listener to receive video frame metadata events.
|
void |
setVideoScalingMode(int videoScalingMode) |
Sets the video scaling mode.
|
void |
setVideoSurface(Surface surface) |
Sets the
Surface onto which video will be rendered. |
void |
setVideoSurfaceHolder(SurfaceHolder surfaceHolder) |
Sets the
SurfaceHolder that holds the Surface onto which video will be
rendered. |
void |
setVideoSurfaceView(SurfaceView surfaceView) |
Sets the
SurfaceView onto which video will be rendered. |
void |
setVideoTextureView(TextureView textureView) |
Sets the
TextureView onto which video will be rendered. |
void |
setVolume(float audioVolume) |
Sets the audio volume, with 0 being silence and 1 being unity gain.
|
void |
setWakeMode(int wakeMode) |
Sets how the player should keep the device awake for playback when the screen is off.
|
void |
stop(boolean reset) |
getBufferedPercentage, getContentDuration, getCurrentLiveOffset, getCurrentManifest, getCurrentMediaItem, getCurrentTag, getMediaItemAt, getMediaItemCount, getNextWindowIndex, getPreviousWindowIndex, hasNext, hasPrevious, isCurrentWindowDynamic, isCurrentWindowLive, isCurrentWindowSeekable, isPlaying, next, pause, play, previous, seekTo, seekToDefaultPosition, seekToDefaultPosition, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBufferedPercentage, getContentDuration, getCurrentLiveOffset, getCurrentManifest, getCurrentMediaItem, getCurrentTag, getMediaItemAt, getMediaItemCount, getNextWindowIndex, getPreviousWindowIndex, hasNext, hasPrevious, isCurrentWindowDynamic, isCurrentWindowLive, isCurrentWindowSeekable, isPlaying, next, pause, play, previous, seekTo, seekToDefaultPosition, seekToDefaultPosition, stop
public static final long DEFAULT_DETACH_SURFACE_TIMEOUT_MS
protected final Renderer[] renderers
@Deprecated protected SimpleExoPlayer(Context context, RenderersFactory renderersFactory, TrackSelector trackSelector, MediaSourceFactory mediaSourceFactory, LoadControl loadControl, BandwidthMeter bandwidthMeter, AnalyticsCollector analyticsCollector, boolean useLazyPreparation, Clock clock, Looper applicationLooper)
SimpleExoPlayer.Builder
and pass it to SimpleExoPlayer(Builder)
.protected SimpleExoPlayer(SimpleExoPlayer.Builder builder)
builder
- The SimpleExoPlayer.Builder
to obtain all construction parameters.public void experimentalSetOffloadSchedulingEnabled(boolean offloadSchedulingEnabled)
ExoPlayer
Only use this scheduling mode if the player is not displaying anything to the user. For example when the application is in the background, or the screen is off. The player state (including position) is rarely updated (roughly between every 10 seconds and 1 minute).
While offload scheduling is enabled, player events may be delivered severely delayed and
apps should not interact with the player. When returning to the foreground, disable offload
scheduling and wait for Player.EventListener.onExperimentalOffloadSchedulingEnabledChanged(boolean)
to be called with
offloadSchedulingEnabled = false
before interacting with the player.
This mode should save significant power when the phone is playing offload audio with the screen off.
This mode only has an effect when playing an audio track in offload mode, which requires all the following:
DefaultRenderersFactory.setEnableAudioOffload(boolean)
or the equivalent option passed to DefaultAudioSink(AudioCapabilities,
DefaultAudioSink.AudioProcessorChain, boolean, boolean, boolean)
.
AudioSink
is playing with an offload AudioTrack
.
The state where ExoPlayer main loop has been paused to save power during offload playback
can be queried with ExoPlayer.experimentalIsSleepingForOffload()
.
This method is experimental, and will be renamed or removed in a future release.
experimentalSetOffloadSchedulingEnabled
in interface ExoPlayer
offloadSchedulingEnabled
- Whether to enable offload scheduling.public boolean experimentalIsSleepingForOffload()
ExoPlayer
@Nullable public Player.AudioComponent getAudioComponent()
Player
getAudioComponent
in interface Player
@Nullable public Player.VideoComponent getVideoComponent()
Player
getVideoComponent
in interface Player
@Nullable public Player.TextComponent getTextComponent()
Player
getTextComponent
in interface Player
@Nullable public Player.MetadataComponent getMetadataComponent()
Player
getMetadataComponent
in interface Player
@Nullable public Player.DeviceComponent getDeviceComponent()
Player
getDeviceComponent
in interface Player
public void setVideoScalingMode(@VideoScalingMode int videoScalingMode)
Note that the scaling mode only applies if a MediaCodec
-based video Renderer
is enabled and if the output surface is owned by a SurfaceView
.
setVideoScalingMode
in interface Player.VideoComponent
videoScalingMode
- The C.VideoScalingMode
.@VideoScalingMode public int getVideoScalingMode()
Player.VideoComponent
C.VideoScalingMode
.getVideoScalingMode
in interface Player.VideoComponent
public void clearVideoSurface()
Player.VideoComponent
clearVideoSurface
in interface Player.VideoComponent
public void clearVideoSurface(@Nullable Surface surface)
Player.VideoComponent
Surface
onto which video is being rendered if it matches the one passed.
Else does nothing.clearVideoSurface
in interface Player.VideoComponent
surface
- The surface to clear.public void setVideoSurface(@Nullable Surface surface)
Player.VideoComponent
Surface
onto which video will be rendered. The caller is responsible for
tracking the lifecycle of the surface, and must clear the surface by calling
setVideoSurface(null)
if the surface is destroyed.
If the surface is held by a SurfaceView
, TextureView
or SurfaceHolder
then it's recommended to use Player.VideoComponent.setVideoSurfaceView(SurfaceView)
, Player.VideoComponent.setVideoTextureView(TextureView)
or Player.VideoComponent.setVideoSurfaceHolder(SurfaceHolder)
rather
than this method, since passing the holder allows the player to track the lifecycle of the
surface automatically.
setVideoSurface
in interface Player.VideoComponent
surface
- The Surface
.public void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)
Player.VideoComponent
SurfaceHolder
that holds the Surface
onto which video will be
rendered. The player will track the lifecycle of the surface automatically.setVideoSurfaceHolder
in interface Player.VideoComponent
surfaceHolder
- The surface holder.public void clearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)
Player.VideoComponent
SurfaceHolder
that holds the Surface
onto which video is being
rendered if it matches the one passed. Else does nothing.clearVideoSurfaceHolder
in interface Player.VideoComponent
surfaceHolder
- The surface holder to clear.public void setVideoSurfaceView(@Nullable SurfaceView surfaceView)
Player.VideoComponent
SurfaceView
onto which video will be rendered. The player will track the
lifecycle of the surface automatically.setVideoSurfaceView
in interface Player.VideoComponent
surfaceView
- The surface view.public void clearVideoSurfaceView(@Nullable SurfaceView surfaceView)
Player.VideoComponent
SurfaceView
onto which video is being rendered if it matches the one
passed. Else does nothing.clearVideoSurfaceView
in interface Player.VideoComponent
surfaceView
- The texture view to clear.public void setVideoTextureView(@Nullable TextureView textureView)
Player.VideoComponent
TextureView
onto which video will be rendered. The player will track the
lifecycle of the surface automatically.setVideoTextureView
in interface Player.VideoComponent
textureView
- The texture view.public void clearVideoTextureView(@Nullable TextureView textureView)
Player.VideoComponent
TextureView
onto which video is being rendered if it matches the one
passed. Else does nothing.clearVideoTextureView
in interface Player.VideoComponent
textureView
- The texture view to clear.public void addAudioListener(AudioListener listener)
Player.AudioComponent
addAudioListener
in interface Player.AudioComponent
listener
- The listener to register.public void removeAudioListener(AudioListener listener)
Player.AudioComponent
removeAudioListener
in interface Player.AudioComponent
listener
- The listener to unregister.public void setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus)
Player.AudioComponent
Setting the audio attributes during playback may introduce a short gap in audio output as the audio track is recreated. A new audio session id will also be generated.
If tunneling is enabled by the track selector, the specified audio attributes will be ignored, but they will take effect if audio is later played without tunneling.
If the device is running a build before platform API version 21, audio attributes cannot
be set directly on the underlying audio track. In this case, the usage will be mapped onto an
equivalent stream type using Util.getStreamTypeForAudioUsage(int)
.
If audio focus should be handled, the AudioAttributes.usage
must be C.USAGE_MEDIA
or C.USAGE_GAME
. Other usages will throw an IllegalArgumentException
.
setAudioAttributes
in interface Player.AudioComponent
audioAttributes
- The attributes to use for audio playback.handleAudioFocus
- True if the player should handle audio focus, false otherwise.public AudioAttributes getAudioAttributes()
Player.AudioComponent
getAudioAttributes
in interface Player.AudioComponent
public void setAudioSessionId(int audioSessionId)
Player.AudioComponent
AudioTrack
.
The audio session ID can be generated using C.generateAudioSessionIdV21(Context)
for API 21+.
setAudioSessionId
in interface Player.AudioComponent
audioSessionId
- The audio session ID, or C.AUDIO_SESSION_ID_UNSET
if it should
be generated by the framework.public int getAudioSessionId()
Player.AudioComponent
C.AUDIO_SESSION_ID_UNSET
if not set.getAudioSessionId
in interface Player.AudioComponent
public void setAuxEffectInfo(AuxEffectInfo auxEffectInfo)
Player.AudioComponent
setAuxEffectInfo
in interface Player.AudioComponent
public void clearAuxEffectInfo()
Player.AudioComponent
clearAuxEffectInfo
in interface Player.AudioComponent
public void setVolume(float audioVolume)
Player.AudioComponent
setVolume
in interface Player.AudioComponent
audioVolume
- The audio volume.public float getVolume()
Player.AudioComponent
getVolume
in interface Player.AudioComponent
public boolean getSkipSilenceEnabled()
Player.AudioComponent
getSkipSilenceEnabled
in interface Player.AudioComponent
public void setSkipSilenceEnabled(boolean skipSilenceEnabled)
Player.AudioComponent
setSkipSilenceEnabled
in interface Player.AudioComponent
skipSilenceEnabled
- Whether skipping silences in the audio stream is enabled.public AnalyticsCollector getAnalyticsCollector()
AnalyticsCollector
used for collecting analytics events.public void addAnalyticsListener(AnalyticsListener listener)
AnalyticsListener
to receive analytics events.listener
- The listener to be added.public void removeAnalyticsListener(AnalyticsListener listener)
AnalyticsListener
.listener
- The listener to be removed.public void setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy)
handleAudioBecomingNoisy
- Whether the player should pause automatically when audio is
rerouted from a headset to device speakers.public void setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager)
PriorityTaskManager
, or null to clear a previously set priority task manager.
The priority C.PRIORITY_PLAYBACK
will be set while the player is loading.
priorityTaskManager
- The PriorityTaskManager
, or null to clear a previously set
priority task manager.@Nullable public Format getVideoFormat()
@Nullable public Format getAudioFormat()
@Nullable public DecoderCounters getVideoDecoderCounters()
DecoderCounters
for video, or null if no video is being played.@Nullable public DecoderCounters getAudioDecoderCounters()
DecoderCounters
for audio, or null if no audio is being played.public void addVideoListener(VideoListener listener)
Player.VideoComponent
addVideoListener
in interface Player.VideoComponent
listener
- The listener to register.public void removeVideoListener(VideoListener listener)
Player.VideoComponent
removeVideoListener
in interface Player.VideoComponent
listener
- The listener to unregister.public void setVideoFrameMetadataListener(VideoFrameMetadataListener listener)
Player.VideoComponent
This method is intended to be called by the same component that sets the Surface
onto which video will be rendered. If using ExoPlayer's standard UI components, this method
should not be called directly from application code.
setVideoFrameMetadataListener
in interface Player.VideoComponent
listener
- The listener.public void clearVideoFrameMetadataListener(VideoFrameMetadataListener listener)
Player.VideoComponent
clearVideoFrameMetadataListener
in interface Player.VideoComponent
listener
- The listener to clear.public void setCameraMotionListener(CameraMotionListener listener)
Player.VideoComponent
setCameraMotionListener
in interface Player.VideoComponent
listener
- The listener.public void clearCameraMotionListener(CameraMotionListener listener)
Player.VideoComponent
clearCameraMotionListener
in interface Player.VideoComponent
listener
- The listener to clear.public void addTextOutput(TextOutput listener)
Player.TextComponent
addTextOutput
in interface Player.TextComponent
listener
- The output to register.public void removeTextOutput(TextOutput listener)
Player.TextComponent
removeTextOutput
in interface Player.TextComponent
listener
- The output to remove.public List<Cue> getCurrentCues()
Player.TextComponent
Cues
. This list may be empty.getCurrentCues
in interface Player.TextComponent
public void addMetadataOutput(MetadataOutput listener)
Player.MetadataComponent
MetadataOutput
to receive metadata.addMetadataOutput
in interface Player.MetadataComponent
listener
- The output to register.public void removeMetadataOutput(MetadataOutput listener)
Player.MetadataComponent
MetadataOutput
.removeMetadataOutput
in interface Player.MetadataComponent
listener
- The output to remove.public Looper getPlaybackLooper()
ExoPlayer
Looper
associated with the playback thread.getPlaybackLooper
in interface ExoPlayer
public Looper getApplicationLooper()
Player
Looper
associated with the application thread that's used to access the
player and on which player events are received.getApplicationLooper
in interface Player
public Clock getClock()
ExoPlayer
Clock
used for playback.public void addListener(Player.EventListener listener)
Player
Looper
, then the listener will be called on the main thread.addListener
in interface Player
listener
- The listener to register.public void removeListener(Player.EventListener listener)
Player
removeListener
in interface Player
listener
- The listener to unregister.@State public int getPlaybackState()
Player
playback state
of the player.getPlaybackState
in interface Player
playback state
.Player.EventListener.onPlaybackStateChanged(int)
@PlaybackSuppressionReason public int getPlaybackSuppressionReason()
Player
Player.getPlayWhenReady()
is
true
, or Player.PLAYBACK_SUPPRESSION_REASON_NONE
if playback is not suppressed.getPlaybackSuppressionReason
in interface Player
playback suppression reason
.Player.EventListener.onPlaybackSuppressionReasonChanged(int)
@Deprecated @Nullable public ExoPlaybackException getPlaybackError()
getPlayerError()
instead.getPlaybackError
in interface Player
@Nullable public ExoPlaybackException getPlayerError()
Player
Player.EventListener.onPlayerError(ExoPlaybackException)
at the time of
failure. It can be queried using this method until the player is re-prepared.
Note that this method will always return null
if Player.getPlaybackState()
is not
Player.STATE_IDLE
.
getPlayerError
in interface Player
null
.Player.EventListener.onPlayerError(ExoPlaybackException)
@Deprecated public void retry()
prepare()
instead.public void prepare()
Player
@Deprecated public void prepare(MediaSource mediaSource)
setMediaSource(MediaSource)
and Player.prepare()
instead.@Deprecated public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetState)
setMediaSource(MediaSource, boolean)
and Player.prepare()
instead.public void setMediaItems(List<MediaItem> mediaItems)
Player
MediaItems
and resets the position to
the default position.setMediaItems
in interface Player
setMediaItems
in class BasePlayer
mediaItems
- The new MediaItems
.public void setMediaItems(List<MediaItem> mediaItems, boolean resetPosition)
Player
MediaItems
.setMediaItems
in interface Player
mediaItems
- The new MediaItems
.resetPosition
- Whether the playback position should be reset to the default position in
the first Timeline.Window
. If false, playback will start from the position defined
by Player.getCurrentWindowIndex()
and Player.getCurrentPosition()
.public void setMediaItems(List<MediaItem> mediaItems, int startWindowIndex, long startPositionMs)
Player
MediaItems
.setMediaItems
in interface Player
mediaItems
- The new MediaItems
.startWindowIndex
- The window index to start playback from. If C.INDEX_UNSET
is
passed, the current position is not reset.startPositionMs
- The position in milliseconds to start playback from. If C.TIME_UNSET
is passed, the default position of the given window is used. In any case, if
startWindowIndex
is set to C.INDEX_UNSET
, this parameter is ignored and the
position is not reset at all.public void setMediaItem(MediaItem mediaItem)
Player
MediaItem
and resets the position to the
default position.setMediaItem
in interface Player
setMediaItem
in class BasePlayer
mediaItem
- The new MediaItem
.public void setMediaItem(MediaItem mediaItem, boolean resetPosition)
Player
MediaItem
.setMediaItem
in interface Player
setMediaItem
in class BasePlayer
mediaItem
- The new MediaItem
.resetPosition
- Whether the playback position should be reset to the default position. If
false, playback will start from the position defined by Player.getCurrentWindowIndex()
and Player.getCurrentPosition()
.public void setMediaItem(MediaItem mediaItem, long startPositionMs)
Player
MediaItem
.setMediaItem
in interface Player
setMediaItem
in class BasePlayer
mediaItem
- The new MediaItem
.startPositionMs
- The position in milliseconds to start playback from.public void setMediaSources(List<MediaSource> mediaSources)
ExoPlayer
MediaSources
and resets the
position to the default position.setMediaSources
in interface ExoPlayer
mediaSources
- The new MediaSources
.public void setMediaSources(List<MediaSource> mediaSources, boolean resetPosition)
ExoPlayer
MediaSources
.setMediaSources
in interface ExoPlayer
mediaSources
- The new MediaSources
.resetPosition
- Whether the playback position should be reset to the default position in
the first Timeline.Window
. If false, playback will start from the position defined
by Player.getCurrentWindowIndex()
and Player.getCurrentPosition()
.public void setMediaSources(List<MediaSource> mediaSources, int startWindowIndex, long startPositionMs)
ExoPlayer
MediaSources
.setMediaSources
in interface ExoPlayer
mediaSources
- The new MediaSources
.startWindowIndex
- The window index to start playback from. If C.INDEX_UNSET
is
passed, the current position is not reset.startPositionMs
- The position in milliseconds to start playback from. If C.TIME_UNSET
is passed, the default position of the given window is used. In any case, if
startWindowIndex
is set to C.INDEX_UNSET
, this parameter is ignored and the
position is not reset at all.public void setMediaSource(MediaSource mediaSource)
ExoPlayer
MediaSource
and resets the position to the
default position.setMediaSource
in interface ExoPlayer
mediaSource
- The new MediaSource
.public void setMediaSource(MediaSource mediaSource, boolean resetPosition)
ExoPlayer
MediaSource
.setMediaSource
in interface ExoPlayer
mediaSource
- The new MediaSource
.resetPosition
- Whether the playback position should be reset to the default position. If
false, playback will start from the position defined by Player.getCurrentWindowIndex()
and Player.getCurrentPosition()
.public void setMediaSource(MediaSource mediaSource, long startPositionMs)
ExoPlayer
MediaSource
.setMediaSource
in interface ExoPlayer
mediaSource
- The new MediaSource
.startPositionMs
- The position in milliseconds to start playback from.public void addMediaItems(List<MediaItem> mediaItems)
Player
addMediaItems
in interface Player
mediaItems
- The MediaItems
to add.public void addMediaItems(int index, List<MediaItem> mediaItems)
Player
addMediaItems
in interface Player
index
- The index at which to add the media items.mediaItems
- The MediaItems
to add.public void addMediaItem(MediaItem mediaItem)
Player
addMediaItem
in interface Player
addMediaItem
in class BasePlayer
mediaItem
- The MediaItem
to add.public void addMediaItem(int index, MediaItem mediaItem)
Player
addMediaItem
in interface Player
addMediaItem
in class BasePlayer
index
- The index at which to add the item.mediaItem
- The MediaItem
to add.public void addMediaSource(MediaSource mediaSource)
ExoPlayer
addMediaSource
in interface ExoPlayer
mediaSource
- The MediaSource
to add.public void addMediaSource(int index, MediaSource mediaSource)
ExoPlayer
addMediaSource
in interface ExoPlayer
index
- The index at which to add the source.mediaSource
- The MediaSource
to add.public void addMediaSources(List<MediaSource> mediaSources)
ExoPlayer
addMediaSources
in interface ExoPlayer
mediaSources
- The MediaSources
to add.public void addMediaSources(int index, List<MediaSource> mediaSources)
ExoPlayer
addMediaSources
in interface ExoPlayer
index
- The index at which to add the media sources.mediaSources
- The MediaSources
to add.public void moveMediaItem(int currentIndex, int newIndex)
Player
moveMediaItem
in interface Player
moveMediaItem
in class BasePlayer
currentIndex
- The current index of the media item to move.newIndex
- The new index of the media item. If the new index is larger than the size of
the playlist the item is moved to the end of the playlist.public void moveMediaItems(int fromIndex, int toIndex, int newIndex)
Player
moveMediaItems
in interface Player
fromIndex
- The start of the range to move.toIndex
- The first item not to be included in the range (exclusive).newIndex
- The new index of the first media item of the range. If the new index is larger
than the size of the remaining playlist after removing the range, the range is moved to the
end of the playlist.public void removeMediaItem(int index)
Player
removeMediaItem
in interface Player
removeMediaItem
in class BasePlayer
index
- The index at which to remove the media item.public void removeMediaItems(int fromIndex, int toIndex)
Player
removeMediaItems
in interface Player
fromIndex
- The index at which to start removing media items.toIndex
- The index of the first item to be kept (exclusive).public void clearMediaItems()
Player
clearMediaItems
in interface Player
public void setShuffleOrder(ShuffleOrder shuffleOrder)
ExoPlayer
setShuffleOrder
in interface ExoPlayer
shuffleOrder
- The shuffle order.public void setPlayWhenReady(boolean playWhenReady)
Player
Player.getPlaybackState()
== Player.STATE_READY
.
If the player is already in the ready state then this method pauses and resumes playback.
setPlayWhenReady
in interface Player
playWhenReady
- Whether playback should proceed when ready.public boolean getPlayWhenReady()
Player
Player.getPlaybackState()
== Player.STATE_READY
.getPlayWhenReady
in interface Player
Player.EventListener.onPlayWhenReadyChanged(boolean, int)
public void setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems)
ExoPlayer
This means the player will pause at the end of each window in the current timeline
. Listeners will be informed by a call to Player.EventListener.onPlayWhenReadyChanged(boolean, int)
with the reason Player.PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM
when this happens.
setPauseAtEndOfMediaItems
in interface ExoPlayer
pauseAtEndOfMediaItems
- Whether to pause playback at the end of each media item.public boolean getPauseAtEndOfMediaItems()
ExoPlayer
getPauseAtEndOfMediaItems
in interface ExoPlayer
ExoPlayer.setPauseAtEndOfMediaItems(boolean)
@RepeatMode public int getRepeatMode()
Player
Player.RepeatMode
used for playback.getRepeatMode
in interface Player
Player.EventListener.onRepeatModeChanged(int)
public void setRepeatMode(@RepeatMode int repeatMode)
Player
Player.RepeatMode
to be used for playback.setRepeatMode
in interface Player
repeatMode
- The repeat mode.public void setShuffleModeEnabled(boolean shuffleModeEnabled)
Player
setShuffleModeEnabled
in interface Player
shuffleModeEnabled
- Whether shuffling is enabled.public boolean getShuffleModeEnabled()
Player
getShuffleModeEnabled
in interface Player
Player.EventListener.onShuffleModeEnabledChanged(boolean)
public boolean isLoading()
Player
isLoading
in interface Player
Player.EventListener.onIsLoadingChanged(boolean)
public void seekTo(int windowIndex, long positionMs)
Player
seekTo
in interface Player
windowIndex
- The index of the window.positionMs
- The seek position in the specified window, or C.TIME_UNSET
to seek to
the window's default position.public void setPlaybackParameters(@Nullable PlaybackParameters playbackParameters)
Player
null
sets the parameters to the
default, PlaybackParameters.DEFAULT
, which means there is no speed or pitch adjustment.
Playback parameters changes may cause the player to buffer. Player.EventListener.onPlaybackParametersChanged(PlaybackParameters)
will be called whenever the
currently active playback parameters change.
setPlaybackParameters
in interface Player
playbackParameters
- The playback parameters, or null
to use the defaults.public PlaybackParameters getPlaybackParameters()
Player
getPlaybackParameters
in interface Player
Player.EventListener.onPlaybackParametersChanged(PlaybackParameters)
public void setSeekParameters(@Nullable SeekParameters seekParameters)
ExoPlayer
setSeekParameters
in interface ExoPlayer
seekParameters
- The seek parameters, or null
to use the defaults.public SeekParameters getSeekParameters()
ExoPlayer
SeekParameters
of the player.getSeekParameters
in interface ExoPlayer
public void setForegroundMode(boolean foregroundMode)
ExoPlayer
This mode should be used with caution, since holding limited resources may prevent other players of media components from acquiring them. It should only be enabled when both of the following conditions are true:
Player.stop()
is called to halt one playback, and
ExoPlayer.prepare(com.google.android.exoplayer2.source.MediaSource)
is called some time later to start a new one).
Note that foreground mode is not useful for switching between content without gaps
between the playbacks. For this use case Player.stop()
does not need to be called, and simply
calling ExoPlayer.prepare(com.google.android.exoplayer2.source.MediaSource)
for the new media will cause limited resources to be retained even if
foreground mode is not enabled.
If foreground mode is enabled, it's the application's responsibility to disable it when the conditions described above no longer hold.
setForegroundMode
in interface ExoPlayer
foregroundMode
- Whether the player is allowed to keep limited resources even when in the
idle state.public void release()
Player
public PlayerMessage createMessage(PlayerMessage.Target target)
ExoPlayer
PlayerMessage.Target
. By default, the message
will be delivered immediately without blocking on the playback thread. The default PlayerMessage.getType()
is 0 and the default PlayerMessage.getPayload()
is null. If a
position is specified with PlayerMessage.setPosition(long)
, the message will be
delivered at this position in the current window defined by Player.getCurrentWindowIndex()
.
Alternatively, the message can be sent at a specific window using PlayerMessage.setPosition(int, long)
.createMessage
in interface ExoPlayer
public int getRendererCount()
Player
getRendererCount
in interface Player
public int getRendererType(int index)
Player
For example, a video renderer will return C.TRACK_TYPE_VIDEO
, an audio renderer will
return C.TRACK_TYPE_AUDIO
and a text renderer will return C.TRACK_TYPE_TEXT
.
getRendererType
in interface Player
index
- The index of the renderer.TRACK_TYPE_*
constants defined in C
.@Nullable public TrackSelector getTrackSelector()
ExoPlayer
getTrackSelector
in interface ExoPlayer
public TrackGroupArray getCurrentTrackGroups()
Player
getCurrentTrackGroups
in interface Player
Player.EventListener.onTracksChanged(TrackGroupArray, TrackSelectionArray)
public TrackSelectionArray getCurrentTrackSelections()
Player
A concrete implementation may include null elements if it has a fixed number of renderer components, wishes to report a TrackSelection for each of them, and has one or more renderer components that is not assigned any selected tracks.
getCurrentTrackSelections
in interface Player
public List<Metadata> getCurrentStaticMetadata()
Player
The returned metadataList
is an immutable list of Metadata
instances, where
the elements correspond to the current track selections
,
or an empty list if there are no track selections or the selected tracks contain no static
metadata.
This metadata is considered static in that it comes from the tracks' declared Formats, rather than being timed (or dynamic) metadata, which is represented within a metadata track.
getCurrentStaticMetadata
in interface Player
Player.EventListener.onStaticMetadataChanged(List)
public Timeline getCurrentTimeline()
Player
Timeline
. Never null, but may be empty.getCurrentTimeline
in interface Player
Player.EventListener.onTimelineChanged(Timeline, int)
public int getCurrentPeriodIndex()
Player
getCurrentPeriodIndex
in interface Player
public int getCurrentWindowIndex()
Player
window
in the timeline
, or the prospective window index if the current timeline
is empty.getCurrentWindowIndex
in interface Player
public long getDuration()
Player
C.TIME_UNSET
if the duration is not known.getDuration
in interface Player
public long getCurrentPosition()
Player
current timeline
is
empty.getCurrentPosition
in interface Player
public long getBufferedPosition()
Player
getBufferedPosition
in interface Player
public long getTotalBufferedDuration()
Player
getTotalBufferedDuration
in interface Player
public boolean isPlayingAd()
Player
isPlayingAd
in interface Player
public int getCurrentAdGroupIndex()
Player
Player.isPlayingAd()
returns true, returns the index of the ad group in the period
currently being played. Returns C.INDEX_UNSET
otherwise.getCurrentAdGroupIndex
in interface Player
public int getCurrentAdIndexInAdGroup()
Player
Player.isPlayingAd()
returns true, returns the index of the ad in its ad group. Returns
C.INDEX_UNSET
otherwise.getCurrentAdIndexInAdGroup
in interface Player
public long getContentPosition()
Player
Player.isPlayingAd()
returns true
, returns the content position that will be
played once all ads in the ad group have finished playing, in milliseconds. If there is no ad
playing, the returned position is the same as that returned by Player.getCurrentPosition()
.getContentPosition
in interface Player
public long getContentBufferedPosition()
Player
Player.isPlayingAd()
returns true
, returns an estimate of the content position in
the current content window up to which data is buffered, in milliseconds. If there is no ad
playing, the returned position is the same as that returned by Player.getBufferedPosition()
.getContentBufferedPosition
in interface Player
@Deprecated public void setHandleWakeLock(boolean handleWakeLock)
setWakeMode(int)
instead.PowerManager.WakeLock
to ensure the
device stays awake for playback, even when the screen is off.
Enabling this feature requires the Manifest.permission.WAKE_LOCK
permission.
It should be used together with a foreground Service
for use cases where
playback can occur when the screen is off (e.g. background audio playback). It is not useful if
the screen will always be on during playback (e.g. foreground video playback).
handleWakeLock
- Whether the player should use a PowerManager.WakeLock
to ensure the device stays awake for playback, even when the screen is off.public void setWakeMode(@WakeMode int wakeMode)
Enabling this feature requires the Manifest.permission.WAKE_LOCK
permission.
It should be used together with a foreground Service
for use cases where
playback occurs and the screen is off (e.g. background audio playback). It is not useful when
the screen will be kept on during playback (e.g. foreground video playback).
When enabled, the locks (PowerManager.WakeLock
/ WifiManager.WifiLock
) will be held whenever the player is in the Player.STATE_READY
or Player.STATE_BUFFERING
states with playWhenReady = true
. The locks
held depends on the specified C.WakeMode
.
wakeMode
- The C.WakeMode
option to keep the device awake during playback.public void addDeviceListener(DeviceListener listener)
Player.DeviceComponent
addDeviceListener
in interface Player.DeviceComponent
public void removeDeviceListener(DeviceListener listener)
Player.DeviceComponent
removeDeviceListener
in interface Player.DeviceComponent
public DeviceInfo getDeviceInfo()
Player.DeviceComponent
getDeviceInfo
in interface Player.DeviceComponent
public int getDeviceVolume()
Player.DeviceComponent
For devices with local playback
, the volume
returned by this method varies according to the current stream type
. The
stream type is determined by AudioAttributes.usage
which can be converted to stream
type with Util.getStreamTypeForAudioUsage(int)
. The audio attributes can be set to
the player by calling Player.AudioComponent.setAudioAttributes(com.google.android.exoplayer2.audio.AudioAttributes, boolean)
.
For devices with remote playback
, the volume of
the remote device is returned.
getDeviceVolume
in interface Player.DeviceComponent
public boolean isDeviceMuted()
Player.DeviceComponent
isDeviceMuted
in interface Player.DeviceComponent
public void setDeviceVolume(int volume)
Player.DeviceComponent
setDeviceVolume
in interface Player.DeviceComponent
volume
- The volume to set.public void increaseDeviceVolume()
Player.DeviceComponent
increaseDeviceVolume
in interface Player.DeviceComponent
public void decreaseDeviceVolume()
Player.DeviceComponent
decreaseDeviceVolume
in interface Player.DeviceComponent
public void setDeviceMuted(boolean muted)
Player.DeviceComponent
setDeviceMuted
in interface Player.DeviceComponent
public void setThrowsWhenUsingWrongThread(boolean throwsWhenUsingWrongThread)
IllegalStateException
when methods are called
from a thread other than the one associated with getApplicationLooper()
.
The default is true
and this method will be removed in the future.
throwsWhenUsingWrongThread
- Whether to throw when methods are called from a wrong thread.