SimpleExoPlayer
@UnstableApi
public class SimpleExoPlayer extends BasePlayer implements ExoPlayer
Summary
Nested types |
|---|
public final class SimpleExoPlayer.BuilderThis class is deprecated. Use |
Protected constructors |
|---|
|
This method is deprecated. Use the |
Public methods |
|
|---|---|
void |
Adds an |
void |
Adds a listener for audio codec parameter changes. |
void |
Adds a listener to receive audio offload events. |
void |
Registers a listener to receive all events from the player. |
void |
Adds a list of media items at the given index of the playlist. |
void |
Adds a media source to the end of the playlist. |
void |
Adds a media source at the given index of the playlist. |
void |
Adds a list of media sources to the end of the playlist. |
void |
Adds a list of media sources at the given index of the playlist. |
void |
Adds a listener for video codec parameter changes. |
void |
Detaches any previously attached auxiliary audio effect from the underlying audio track. |
void |
Clears the listener which receives camera motion events if it matches the one passed. |
void |
Clears the listener which receives video frame metadata events if it matches the one passed. |
void |
Clears any |
void |
Clears the |
void |
Clears the |
void |
Clears the |
void |
Clears the |
PlayerMessage |
Creates a message that can be sent to a |
void |
This method is deprecated. Use |
void |
Decreases the volume of the device. |
AnalyticsCollector |
Returns the |
Looper |
Returns the |
AudioAttributes |
Returns the attributes for audio playback. |
@Nullable DecoderCounters |
Returns |
@Nullable Format |
Returns the audio format currently being played, or null if no audio is being played. |
int |
Returns the audio session identifier, or |
Player.Commands |
Returns the player's currently available |
long |
Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds. |
Clock |
Returns the |
long |
If |
long |
If |
int |
If |
int |
If |
CueGroup |
Returns the current |
int |
Returns the index of the current |
int |
Returns the index of the period currently being played. |
long |
Returns the playback position in the current content or ad, in milliseconds, or the prospective position in milliseconds if the |
Timeline |
Returns the current |
TrackGroupArray |
This method is deprecated. Use |
TrackSelectionArray |
This method is deprecated. Use |
Tracks |
Returns the current tracks. |
DeviceInfo |
Gets the device information. |
int |
Gets the current volume of the device. |
long |
Returns the duration of the current content or ad in milliseconds, or |
long |
Returns the maximum position for which |
MediaMetadata |
Returns the current combined |
boolean |
Returns whether the player pauses playback at the end of each media item. |
boolean |
Whether playback will proceed when |
Looper |
Returns the |
PlaybackParameters |
Returns the currently active playback parameters. |
int |
Returns the current |
int |
Returns the reason why playback is suppressed even though |
@Nullable ExoPlaybackException |
Returns the error that caused playback to fail. |
MediaMetadata |
Returns the playlist |
ExoPlayer.PreloadConfiguration |
Returns the |
Renderer |
Returns the renderer at the given index. |
int |
Returns the number of renderers. |
int |
@C.TrackTypeReturns the track type that the renderer at a given index handles. |
int |
Returns the current |
ScrubbingModeParameters |
Gets the parameters that control behavior in |
Renderer |
Returns the secondary renderer at the given index. |
long |
Returns the |
long |
Returns the |
SeekParameters |
Returns the currently active |
boolean |
Returns whether shuffling of media items is enabled. |
ShuffleOrder |
Returns the shuffle order. |
boolean |
Returns whether skipping silences in the audio stream is enabled. |
Size |
Gets the size of the surface on which the video is rendered. |
long |
Returns an estimate of the total buffered duration from the current position, in milliseconds. |
TrackSelectionParameters |
Returns the parameters constraining the track selection. |
TrackSelector |
Returns the track selector that this player uses, or null if track selection is not supported. |
int |
Returns the |
@Nullable DecoderCounters |
Returns |
@Nullable Format |
Returns the video format currently being played, or null if no video is being played. |
int |
Returns the |
VideoSize |
Gets the size of the video. |
float |
Returns the audio volume, with 0 being silence and 1 being unity gain (signal unchanged). |
void |
This method is deprecated. Use |
void |
Increases the volume of the device. |
boolean |
Gets whether the device is muted or not. |
boolean |
Whether the player is currently loading the source. |
boolean |
Returns whether the player is currently playing an ad. |
boolean |
Returns whether |
boolean |
Returns whether the player is optimized for scrubbing (many frequent seeks). |
boolean |
Returns whether the player has paused its main loop to save power in offload scheduling mode. |
boolean |
Returns whether tunneling is enabled for the currently selected tracks. |
void |
Moves the media item range to the new index. |
void |
Sets the audio volume to 0. |
void |
Prepares the player. |
void |
This method is deprecated. Use |
void |
This method is deprecated. Use |
void |
Releases the player. |
void |
Removes an |
void |
Removes a listener for audio codec parameter changes. |
void |
Removes a listener of audio offload events. |
void |
Unregister a listener registered through |
void |
Removes a range of media items from the playlist. |
void |
Removes a listener for video codec parameter changes. |
void |
Replaces the media items at the given range of the playlist. |
void |
Sets the attributes for audio playback, used by the underlying audio track. |
void |
Sets a collection of parameters on the underlying audio codecs. |
void |
Sets the ID of the audio session to attach to the underlying |
void |
Sets information on an auxiliary audio effect to attach to the underlying audio track. |
void |
Sets a listener of camera motion events. |
void |
This method is deprecated. Use |
void |
Sets the mute state of the device. |
void |
This method is deprecated. Use |
void |
Sets the volume of the device with volume flags. |
void |
Sets whether the player is allowed to keep holding limited resources such as video decoders, even when in the idle state. |
void |
Sets whether the player should pause automatically when audio is rerouted from a headset to device speakers. |
void |
Sets the |
void |
Sets the maximum position for which |
void |
Clears the playlist and adds the specified |
void |
Clears the playlist and adds the specified |
void |
Clears the playlist, adds the specified |
void |
Clears the playlist and adds the specified |
void |
Clears the playlist and adds the specified |
void |
Clears the playlist, adds the specified |
void |
Clears the playlist and adds the specified |
void |
Clears the playlist and adds the specified |
void |
Sets whether to pause playback at the end of each media item. |
void |
Sets whether playback should proceed when |
void |
Attempts to set the playback parameters. |
void |
Sets the playlist |
void |
Sets the preferred audio device. |
void |
Sets the |
void |
Sets the |
void |
Sets a |
void |
Sets the |
void |
Sets whether to optimize the player for scrubbing (many frequent seeks). |
void |
Sets the parameters that control behavior in |
void |
Sets the |
void |
Sets the |
void |
Sets the parameters that control how seek operations are performed. |
void |
Sets whether shuffling of media items is enabled. |
void |
Sets the shuffle order. |
void |
Sets whether skipping silences in the audio stream is enabled. |
void |
Sets the parameters constraining the track selection. |
void |
Sets a |
void |
Sets a collection of parameters on the underlying video codecs. |
void |
Sets a |
void |
Sets a listener to receive video frame metadata events. |
void |
Sets the |
void |
Sets the |
void |
Sets the |
void |
Sets the |
void |
Sets the |
void |
Sets the virtual device id to be used for playback. |
void |
Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive. |
void |
Sets how the player should keep the device awake for playback when the screen is off. |
void |
Stops playback without resetting the playlist. |
void |
If the audio volume is 0, sets the audio volume to a non-zero value decided by the Player to be the most appropriate. |
Protected methods |
|
|---|---|
void |
Seeks to a position in the specified |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited fields |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Protected constructors
SimpleExoPlayer
protectedSimpleExoPlayer(SimpleExoPlayer.Builder builder)
| Parameters | |
|---|---|
SimpleExoPlayer.Builder builder |
The |
SimpleExoPlayer
protectedSimpleExoPlayer(
Context context,
RenderersFactory renderersFactory,
TrackSelector trackSelector,
MediaSource.Factory mediaSourceFactory,
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
AnalyticsCollector analyticsCollector,
boolean useLazyPreparation,
Clock clock,
Looper applicationLooper
)
Public methods
addAnalyticsListener
public voidaddAnalyticsListener(AnalyticsListener listener)
Adds an AnalyticsListener to receive analytics events.
This method can be called from any thread.
| Parameters | |
|---|---|
AnalyticsListener listener |
The listener to be added. |
addAudioCodecParametersChangeListener
public voidaddAudioCodecParametersChangeListener(
CodecParametersChangeListener listener,
List<String> keys
)
Adds a listener for audio codec parameter changes.
The listener will be called on the application thread. Upon registration, the listener will be immediately called with the last known values for the subscribed keys.
The default MediaCodec based renderers only support this feature on API level 29 and above.
Note: When used with MediaCodec, observing vendor-specific parameter changes requires API level 31 or higher. On API levels 29 and 30, any requested vendor-specific keys will be ignored.
| Parameters | |
|---|---|
CodecParametersChangeListener listener |
The |
List<String> keys |
The list of parameter keys to subscribe to. |
addAudioOffloadListener
public voidaddAudioOffloadListener(ExoPlayer.AudioOffloadListener listener)
Adds a listener to receive audio offload events.
This method can be called from any thread.
| Parameters | |
|---|---|
ExoPlayer.AudioOffloadListener listener |
The listener to register. |
addListener
public voidaddListener(Player.Listener listener)
Registers a listener to receive all events from the player.
The listener's methods will be called on the thread associated with getApplicationLooper.
This method can be called from any thread.
| Parameters | |
|---|---|
Player.Listener listener |
The listener to register. |
addMediaItems
public voidaddMediaItems(int index, List<MediaItem> mediaItems)
Adds a list of media items at the given index of the playlist.
This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
int index |
The index at which to add the media items. If the index is larger than the size of the playlist, the media items are added to the end of the playlist. |
List<MediaItem> mediaItems |
The |
addMediaSource
public voidaddMediaSource(MediaSource mediaSource)
Adds a media source to the end of the playlist.
| Parameters | |
|---|---|
MediaSource mediaSource |
The |
addMediaSource
public voidaddMediaSource(int index, MediaSource mediaSource)
Adds a media source at the given index of the playlist.
| Parameters | |
|---|---|
int index |
The index at which to add the source. |
MediaSource mediaSource |
The |
addMediaSources
public voidaddMediaSources(List<MediaSource> mediaSources)
Adds a list of media sources to the end of the playlist.
| Parameters | |
|---|---|
List<MediaSource> mediaSources |
The |
addMediaSources
public voidaddMediaSources(int index, List<MediaSource> mediaSources)
Adds a list of media sources at the given index of the playlist.
| Parameters | |
|---|---|
int index |
The index at which to add the media sources. |
List<MediaSource> mediaSources |
The |
addVideoCodecParametersChangeListener
public voidaddVideoCodecParametersChangeListener(
CodecParametersChangeListener listener,
List<String> keys
)
Adds a listener for video codec parameter changes.
The listener will be called on the application thread. Upon registration, the listener will be immediately called with the last known values for the subscribed keys.
The default MediaCodec based renderers only support this feature on API level 29 and above.
Note: When used with MediaCodec, observing vendor-specific parameter changes requires API level 31 or higher. On API levels 29 and 30, any requested vendor-specific keys will be ignored.
| Parameters | |
|---|---|
CodecParametersChangeListener listener |
The |
List<String> keys |
The list of parameter keys to subscribe to. |
clearAuxEffectInfo
public void clearAuxEffectInfo()Detaches any previously attached auxiliary audio effect from the underlying audio track.
clearCameraMotionListener
public voidclearCameraMotionListener(CameraMotionListener listener)
Clears the listener which receives camera motion events if it matches the one passed. Else does nothing.
| Parameters | |
|---|---|
CameraMotionListener listener |
The listener to clear. |
clearVideoFrameMetadataListener
public voidclearVideoFrameMetadataListener(VideoFrameMetadataListener listener)
Clears the listener which receives video frame metadata events if it matches the one passed. Else does nothing.
| Parameters | |
|---|---|
VideoFrameMetadataListener listener |
The listener to clear. |
clearVideoSurface
public void clearVideoSurface()Clears any Surface, SurfaceHolder, SurfaceView or TextureView currently set on the player.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
clearVideoSurface
public voidclearVideoSurface(@Nullable Surface surface)
Clears the Surface onto which video is being rendered if it matches the one passed. Else does nothing.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
clearVideoSurfaceHolder
public voidclearVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)
Clears the SurfaceHolder that holds the Surface onto which video is being rendered if it matches the one passed. Else does nothing.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
@Nullable SurfaceHolder surfaceHolder |
The surface holder to clear. |
clearVideoSurfaceView
public voidclearVideoSurfaceView(@Nullable SurfaceView surfaceView)
Clears the SurfaceView onto which video is being rendered if it matches the one passed. Else does nothing.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
@Nullable SurfaceView surfaceView |
The texture view to clear. |
clearVideoTextureView
public voidclearVideoTextureView(@Nullable TextureView textureView)
Clears the TextureView onto which video is being rendered if it matches the one passed. Else does nothing.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
@Nullable TextureView textureView |
The texture view to clear. |
createMessage
public PlayerMessagecreateMessage(PlayerMessage.Target target)
Creates a message that can be sent to a PlayerMessage.Target. By default, the message will be delivered immediately without blocking on the playback thread. The default getType is 0 and the default getPayload is null. If a position is specified with setPosition, the message will be delivered at this position in the current media item defined by getCurrentMediaItemIndex. Alternatively, the message can be sent at a specific mediaItem using setPosition.
decreaseDeviceVolume
public voiddecreaseDeviceVolume(@C.VolumeFlags int flags)
Decreases the volume of the device.
The getDeviceVolume device volume cannot be decreased below minVolume.
Note that this method affects the device volume. To change the volume of the current stream only, use setVolume.
This method must only be called if COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.
| Parameters | |
|---|---|
@C.VolumeFlags int flags |
Either 0 or a bitwise combination of one or more |
getAnalyticsCollector
public AnalyticsCollectorgetAnalyticsCollector()
Returns the AnalyticsCollector used for collecting analytics events.
getApplicationLooper
public LoopergetApplicationLooper()
Returns the Looper associated with the application thread that's used to access the player and on which player events are received.
This method can be called from any thread.
getAudioAttributes
public AudioAttributesgetAudioAttributes()
Returns the attributes for audio playback.
This method must only be called if COMMAND_GET_AUDIO_ATTRIBUTES is available.
| See also | |
|---|---|
onAudioAttributesChanged |
getAudioDecoderCounters
public @Nullable DecoderCountersgetAudioDecoderCounters()
Returns DecoderCounters for audio, or null if no audio is being played.
getAudioFormat
public @Nullable FormatgetAudioFormat()
Returns the audio format currently being played, or null if no audio is being played.
getAudioSessionId
public int getAudioSessionId()Returns the audio session identifier, or AUDIO_SESSION_ID_UNSET if not set.
| See also | |
|---|---|
onAudioSessionIdChanged |
getAvailableCommands
public Player.CommandsgetAvailableCommands()
Returns the player's currently available Commands.
The returned Commands are not updated when available commands change. Use onAvailableCommandsChanged to get an update when the available commands change.
| Returns | |
|---|---|
Player.Commands |
The currently available |
| See also | |
|---|---|
onAvailableCommandsChanged |
getBufferedPosition
public long getBufferedPosition()Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
getClock
public ClockgetClock()
Returns the Clock used for playback.
This method can be called from any thread.
getContentBufferedPosition
public long getContentBufferedPosition()If isPlayingAd returns true, returns an estimate of the content position in the current content up to which data is buffered, in milliseconds. If there is no ad playing, the returned position is the same as that returned by getBufferedPosition.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
getContentPosition
public long getContentPosition()If 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 getCurrentPosition.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
getCurrentAdGroupIndex
public int getCurrentAdGroupIndex()If isPlayingAd returns true, returns the index of the ad group in the period currently being played. Returns INDEX_UNSET otherwise.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
getCurrentAdIndexInAdGroup
public int getCurrentAdIndexInAdGroup()If isPlayingAd returns true, returns the index of the ad in its ad group. Returns INDEX_UNSET otherwise.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
getCurrentCues
public CueGroupgetCurrentCues()
Returns the current CueGroup.
This method must only be called if COMMAND_GET_TEXT is available.
| See also | |
|---|---|
onCues |
getCurrentMediaItemIndex
public int getCurrentMediaItemIndex()Returns the index of the current MediaItem in the timeline, or the prospective index if the current timeline is empty.
This method must only be called if COMMAND_GET_TIMELINE is available.
getCurrentPeriodIndex
public int getCurrentPeriodIndex()Returns the index of the period currently being played.
This method must only be called if COMMAND_GET_TIMELINE is available.
getCurrentPosition
public long getCurrentPosition()Returns the playback position in the current content or ad, in milliseconds, or the prospective position in milliseconds if the current timeline is empty.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
getCurrentTimeline
public TimelinegetCurrentTimeline()
Returns the current Timeline. Never null, but may be empty.
This method must only be called if COMMAND_GET_TIMELINE is available.
| See also | |
|---|---|
onTimelineChanged |
getCurrentTracks
public TracksgetCurrentTracks()
Returns the current tracks.
This method must only be called if COMMAND_GET_TRACKS is available.
| See also | |
|---|---|
onTracksChanged |
getDeviceVolume
public int getDeviceVolume()Gets the current volume of the device.
For devices with local playback, the volume returned by this method varies according to the current stream type. The stream type is determined by getStreamType.
For devices with remote playback, the volume of the remote device is returned.
Note that this method returns the volume of the device. To check the current stream volume, use getVolume.
This method must only be called if COMMAND_GET_DEVICE_VOLUME is available.
| See also | |
|---|---|
onDeviceVolumeChanged |
getDuration
public long getDuration()Returns the duration of the current content or ad in milliseconds, or TIME_UNSET if the duration is not known.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
getMaxSeekToPreviousPosition
public long getMaxSeekToPreviousPosition()Returns the maximum position for which seekToPrevious seeks to the previous MediaItem, in milliseconds.
| Returns | |
|---|---|
long |
The maximum seek to previous position, in milliseconds. |
| See also | |
|---|---|
onMaxSeekToPreviousPositionChanged |
getMediaMetadata
public MediaMetadatagetMediaMetadata()
Returns the current combined MediaMetadata, or EMPTY if not supported.
This MediaMetadata is a combination of the MediaItem metadata, the static metadata in the media's Format, and any timed metadata that has been parsed from the media and output via onMetadata. If a field is populated in the mediaMetadata, it will be prioritised above the same field coming from static or timed metadata.
This method must only be called if COMMAND_GET_METADATA is available.
| See also | |
|---|---|
onMediaMetadataChanged |
getPauseAtEndOfMediaItems
public boolean getPauseAtEndOfMediaItems()Returns whether the player pauses playback at the end of each media item.
| See also | |
|---|---|
setPauseAtEndOfMediaItems |
getPlayWhenReady
public boolean getPlayWhenReady()Whether playback will proceed when getPlaybackState == STATE_READY.
| Returns | |
|---|---|
boolean |
Whether playback will proceed when ready. |
| See also | |
|---|---|
onPlayWhenReadyChanged |
getPlaybackLooper
public LoopergetPlaybackLooper()
Returns the Looper associated with the playback thread.
This method may be called from any thread.
getPlaybackParameters
public PlaybackParametersgetPlaybackParameters()
Returns the currently active playback parameters.
| See also | |
|---|---|
onPlaybackParametersChanged |
getPlaybackState
@Player.State
public intgetPlaybackState()
Returns the current playback state of the player.
| Returns | |
|---|---|
int |
The current |
| See also | |
|---|---|
onPlaybackStateChanged |
getPlaybackSuppressionReason
@Player.PlaybackSuppressionReason
public intgetPlaybackSuppressionReason()
Returns the reason why playback is suppressed even though getPlayWhenReady is
true, or PLAYBACK_SUPPRESSION_REASON_NONE if playback is not suppressed.
| Returns | |
|---|---|
int |
The current |
| See also | |
|---|---|
onPlaybackSuppressionReasonChanged |
getPlayerError
public @Nullable ExoPlaybackExceptiongetPlayerError()
Returns the error that caused playback to fail. This is the same error that will have been reported via onPlayerError 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 getPlaybackState is not STATE_IDLE.
| Returns | |
|---|---|
@Nullable ExoPlaybackException |
The error, or |
| See also | |
|---|---|
onPlayerError |
getPlaylistMetadata
public MediaMetadatagetPlaylistMetadata()
Returns the playlist MediaMetadata, as set by setPlaylistMetadata, or EMPTY if not supported.
This method must only be called if COMMAND_GET_METADATA is available.
| See also | |
|---|---|
onPlaylistMetadataChanged |
getPreloadConfiguration
public ExoPlayer.PreloadConfigurationgetPreloadConfiguration()
Returns the preload configuration.
getRenderer
public RenderergetRenderer(int index)
Returns the renderer at the given index.
| Parameters | |
|---|---|
int index |
The index of the renderer. |
| Returns | |
|---|---|
Renderer |
The renderer at this index. |
getRendererType
@C.TrackType
public intgetRendererType(int index)
Returns the track type that the renderer at a given index handles.
For example, a video renderer will return TRACK_TYPE_VIDEO, an audio renderer will return TRACK_TYPE_AUDIO and a text renderer will return TRACK_TYPE_TEXT.
| Parameters | |
|---|---|
int index |
The index of the renderer. |
| Returns | |
|---|---|
int |
The |
getRepeatMode
@Player.RepeatMode
public intgetRepeatMode()
Returns the current RepeatMode used for playback.
| Returns | |
|---|---|
int |
The current repeat mode. |
| See also | |
|---|---|
onRepeatModeChanged |
getScrubbingModeParameters
public ScrubbingModeParametersgetScrubbingModeParameters()
Gets the parameters that control behavior in scrubbing mode.
getSecondaryRenderer
public RenderergetSecondaryRenderer(int index)
Returns the secondary renderer at the given index.
| Parameters | |
|---|---|
int index |
The index of the secondary renderer. |
| Returns | |
|---|---|
Renderer |
The secondary renderer at this index, or null if there is no secondary renderer at this index. |
getSeekBackIncrement
public long getSeekBackIncrement()Returns the seekBack increment.
| Returns | |
|---|---|
long |
The seek back increment, in milliseconds. |
| See also | |
|---|---|
onSeekBackIncrementChanged |
getSeekForwardIncrement
public long getSeekForwardIncrement()Returns the seekForward increment.
| Returns | |
|---|---|
long |
The seek forward increment, in milliseconds. |
| See also | |
|---|---|
onSeekForwardIncrementChanged |
getSeekParameters
public SeekParametersgetSeekParameters()
Returns the currently active SeekParameters of the player.
getShuffleModeEnabled
public boolean getShuffleModeEnabled()Returns whether shuffling of media items is enabled.
| See also | |
|---|---|
onShuffleModeEnabledChanged |
getShuffleOrder
public ShuffleOrdergetShuffleOrder()
Returns the shuffle order.
The ShuffleOrder returned will have the same length as the current playlist (getMediaItemCount).
getSkipSilenceEnabled
public boolean getSkipSilenceEnabled()Returns whether skipping silences in the audio stream is enabled.
| See also | |
|---|---|
onSkipSilenceEnabledChanged |
getSurfaceSize
public SizegetSurfaceSize()
Gets the size of the surface on which the video is rendered.
| See also | |
|---|---|
onSurfaceSizeChanged |
getTotalBufferedDuration
public long getTotalBufferedDuration()Returns an estimate of the total buffered duration from the current position, in milliseconds. This includes pre-buffered data for subsequent ads and media items.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
getTrackSelectionParameters
public TrackSelectionParametersgetTrackSelectionParameters()
Returns the parameters constraining the track selection.
| See also | |
|---|---|
onTrackSelectionParametersChanged |
} |
getTrackSelector
public TrackSelectorgetTrackSelector()
Returns the track selector that this player uses, or null if track selection is not supported.
getVideoChangeFrameRateStrategy
@C.VideoChangeFrameRateStrategy
public intgetVideoChangeFrameRateStrategy()
Returns the C.VideoChangeFrameRateStrategy.
getVideoDecoderCounters
public @Nullable DecoderCountersgetVideoDecoderCounters()
Returns DecoderCounters for video, or null if no video is being played.
getVideoFormat
public @Nullable FormatgetVideoFormat()
Returns the video format currently being played, or null if no video is being played.
getVideoScalingMode
@C.VideoScalingMode
public intgetVideoScalingMode()
Returns the C.VideoScalingMode.
getVideoSize
public VideoSizegetVideoSize()
Gets the size of the video.
The video's width and height are 0 if there is no supported video track or its size has not been determined yet.
| See also | |
|---|---|
onVideoSizeChanged |
getVolume
public float getVolume()Returns the audio volume, with 0 being silence and 1 being unity gain (signal unchanged).
This method must only be called if COMMAND_GET_VOLUME is available.
| Returns | |
|---|---|
float |
The linear gain applied to all audio channels. |
| See also | |
|---|---|
onVolumeChanged |
increaseDeviceVolume
public voidincreaseDeviceVolume(@C.VolumeFlags int flags)
Increases the volume of the device.
The getDeviceVolume device volume cannot be increased above maxVolume, if defined.
Note that this method affects the device volume. To change the volume of the current stream only, use setVolume.
This method must only be called if COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.
| Parameters | |
|---|---|
@C.VolumeFlags int flags |
Either 0 or a bitwise combination of one or more |
isDeviceMuted
public boolean isDeviceMuted()Gets whether the device is muted or not.
Note that this method returns the mute state of the device. To check if the current stream is muted, use getVolume() == 0.
This method must only be called if COMMAND_GET_DEVICE_VOLUME is available.
| See also | |
|---|---|
onDeviceVolumeChanged |
isLoading
public boolean isLoading()Whether the player is currently loading the source.
| Returns | |
|---|---|
boolean |
Whether the player is currently loading the source. |
| See also | |
|---|---|
onIsLoadingChanged |
isPlayingAd
public boolean isPlayingAd()Returns whether the player is currently playing an ad.
This method must only be called if COMMAND_GET_CURRENT_MEDIA_ITEM is available.
isReleased
public boolean isReleased()Returns whether release has been called on the player.
This method is allowed to be called after release.
isScrubbingModeEnabled
public boolean isScrubbingModeEnabled()Returns whether the player is optimized for scrubbing (many frequent seeks).
isSleepingForOffload
public boolean isSleepingForOffload()Returns whether the player has paused its main loop to save power in offload scheduling mode.
Offload scheduling mode should save significant power when the phone is playing offload audio with the screen off.
Offload scheduling is only enabled when playing an audio track in offload mode, which requires all the following:
- Audio offload rendering is enabled through
setAudioOffloadPreferences. - An audio track is playing in a format that the device supports offloading (for example, MP3 or AAC).
- The
AudioSinkis playing with an offloadAudioTrack.
| See also | |
|---|---|
onSleepingForOffloadChanged |
isTunnelingEnabled
public boolean isTunnelingEnabled()Returns whether tunneling is enabled for the currently selected tracks.
| See also | |
|---|---|
onTracksChanged |
moveMediaItems
public void moveMediaItems(int fromIndex, int toIndex, int newIndex)Moves the media item range to the new index.
This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
int fromIndex |
The start of the range to move. If the index is larger than the size of the playlist, the request is ignored. |
int toIndex |
The first item not to be included in the range (exclusive). If the index is larger than the size of the playlist, items up to the end of the playlist are moved. |
int 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. |
mute
public void mute()Sets the audio volume to 0.
This method must only be called if COMMAND_SET_VOLUME is available.
prepare
public void prepare()Prepares the player.
This method must only be called if COMMAND_PREPARE is available.
This will move the player out of idle state and the player will start loading media and acquire resources needed for playback.
release
public void release()Releases the player. This method must be called when the player is no longer required. The player must not be used after calling this method.
This method must only be called if COMMAND_RELEASE is available.
removeAnalyticsListener
public voidremoveAnalyticsListener(AnalyticsListener listener)
Removes an AnalyticsListener.
| Parameters | |
|---|---|
AnalyticsListener listener |
The listener to be removed. |
removeAudioCodecParametersChangeListener
public voidremoveAudioCodecParametersChangeListener(
CodecParametersChangeListener listener
)
Removes a listener for audio codec parameter changes.
| Parameters | |
|---|---|
CodecParametersChangeListener listener |
The |
removeAudioOffloadListener
public voidremoveAudioOffloadListener(ExoPlayer.AudioOffloadListener listener)
Removes a listener of audio offload events.
| Parameters | |
|---|---|
ExoPlayer.AudioOffloadListener listener |
The listener to unregister. |
removeListener
public voidremoveListener(Player.Listener listener)
Unregister a listener registered through addListener. The listener will no longer receive events.
| Parameters | |
|---|---|
Player.Listener listener |
The listener to unregister. |
removeMediaItems
public void removeMediaItems(int fromIndex, int toIndex)Removes a range of media items from the playlist.
This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
int fromIndex |
The index at which to start removing media items. If the index is larger than the size of the playlist, the request is ignored. |
int toIndex |
The index of the first item to be kept (exclusive). If the index is larger than the size of the playlist, media items up to the end of the playlist are removed. |
removeVideoCodecParametersChangeListener
public voidremoveVideoCodecParametersChangeListener(
CodecParametersChangeListener listener
)
Removes a listener for video codec parameter changes.
| Parameters | |
|---|---|
CodecParametersChangeListener listener |
The |
replaceMediaItems
public voidreplaceMediaItems(
int fromIndex,
int toIndex,
List<MediaItem> mediaItems
)
Replaces the media items at the given range of the playlist.
Implementations of this method may attempt to seamlessly continue playback if the currently playing media item is replaced with a compatible one (e.g. same URL, only metadata has changed).
This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
Note that it is possible to replace a range with an arbitrary number of new items, so that the number of removed items defined by fromIndex and toIndex does not have to match the number of added items defined by mediaItems. As result, it may also change the index of subsequent items not touched by this operation.
| Parameters | |
|---|---|
int fromIndex |
The start of the range. If the index is larger than the size of the playlist, the request is ignored. |
int toIndex |
The first item not to be included in the range (exclusive). If the index is larger than the size of the playlist, items up to the end of the playlist are replaced. |
List<MediaItem> mediaItems |
The |
setAudioAttributes
public voidsetAudioAttributes(
AudioAttributes audioAttributes,
boolean handleAudioFocus
)
Sets the attributes for audio playback, used by the underlying audio track. If not set, the default audio attributes will be used. They are suitable for general media playback.
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 audio focus should be handled, the usage must be USAGE_MEDIA or USAGE_GAME. Other usages will throw an IllegalArgumentException.
This method must only be called if COMMAND_SET_AUDIO_ATTRIBUTES is available.
| Parameters | |
|---|---|
AudioAttributes audioAttributes |
The attributes to use for audio playback. |
boolean handleAudioFocus |
True if the player should handle audio focus, false otherwise. |
setAudioCodecParameters
public voidsetAudioCodecParameters(CodecParameters codecParameters)
Sets a collection of parameters on the underlying audio codecs.
This method is asynchronous. The parameters will be applied to the audio renderers on the playback thread.
The default MediaCodec based renderers only support this feature on API level 29 and above. If an underlying decoder does not support a parameter, it will be ignored.
| Parameters | |
|---|---|
CodecParameters codecParameters |
The |
setAudioSessionId
public void setAudioSessionId(int audioSessionId)Sets the ID of the audio session to attach to the underlying android.media.AudioTrack.
The audio session ID can be generated using generateAudioSessionIdV21.
| Parameters | |
|---|---|
int audioSessionId |
The audio session ID, or |
setAuxEffectInfo
public voidsetAuxEffectInfo(AuxEffectInfo auxEffectInfo)
Sets information on an auxiliary audio effect to attach to the underlying audio track.
setCameraMotionListener
public voidsetCameraMotionListener(CameraMotionListener listener)
Sets a listener of camera motion events.
| Parameters | |
|---|---|
CameraMotionListener listener |
The listener. |
setDeviceMuted
public voidsetDeviceMuted(boolean muted, @C.VolumeFlags int flags)
Sets the mute state of the device.
Note that this method affects the device volume. To mute just the current stream, use
setVolume(0) instead.
This method must only be called if COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS is available.
| Parameters | |
|---|---|
boolean muted |
Whether to set the device to be muted or not |
@C.VolumeFlags int flags |
Either 0 or a bitwise combination of one or more |
setDeviceVolume
public voidsetDeviceVolume(int volume, @C.VolumeFlags int flags)
Sets the volume of the device with volume flags.
Note that this method affects the device volume. To change the volume of the current stream only, use setVolume.
This method must only be called if COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS is available.
| Parameters | |
|---|---|
int volume |
The volume to set. |
@C.VolumeFlags int flags |
Either 0 or a bitwise combination of one or more |
setForegroundMode
public 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. By doing so, the player may be able to reduce latency when starting to play another piece of content for which the same resources are required.
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:
- The application that owns the player is in the foreground.
- The player is used in a way that may benefit from foreground mode. For this to be true, the same player instance must be used to play multiple pieces of content, and there must be gaps between the playbacks (i.e.
stopis called to halt one playback, and prepare 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 stop does not need to be called, and simply calling prepare 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.
| Parameters | |
|---|---|
boolean foregroundMode |
Whether the player is allowed to keep limited resources even when in the idle state. |
setHandleAudioBecomingNoisy
public void setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy)Sets whether the player should pause automatically when audio is rerouted from a headset to device speakers. See the audio becoming noisy documentation for more information.
| Parameters | |
|---|---|
boolean handleAudioBecomingNoisy |
Whether the player should pause automatically when audio is rerouted from a headset to device speakers. |
setImageOutput
public voidsetImageOutput(@Nullable ImageOutput imageOutput)
Sets the ImageOutput where rendered images will be forwarded.
| Parameters | |
|---|---|
@Nullable ImageOutput imageOutput |
The |
setMaxSeekToPreviousPositionMs
public void setMaxSeekToPreviousPositionMs(long maxSeekToPreviousPositionMs)Sets the maximum position for which seekToPrevious seeks to the previous MediaItem.
| Parameters | |
|---|---|
long maxSeekToPreviousPositionMs |
The maximum position, in milliseconds. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If |
setMediaItems
public voidsetMediaItems(List<MediaItem> mediaItems, boolean resetPosition)
Clears the playlist and adds the specified media items.
To replace a span of media items (possibly seamlessly) without clearing the playlist, use replaceMediaItems.
This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
List<MediaItem> mediaItems |
The new |
boolean resetPosition |
Whether the playback position should be reset to the default position in the first |
setMediaItems
public voidsetMediaItems(
List<MediaItem> mediaItems,
int startIndex,
long startPositionMs
)
Clears the playlist and adds the specified media items.
To replace a span of media items (possibly seamlessly) without clearing the playlist, use replaceMediaItems.
This method must only be called if COMMAND_CHANGE_MEDIA_ITEMS is available.
| Parameters | |
|---|---|
List<MediaItem> mediaItems |
The new |
int startIndex |
The |
long startPositionMs |
The position in milliseconds to start playback from. If |
| Throws | |
|---|---|
androidx.media3.common.IllegalSeekPositionException |
If the provided |
setMediaSource
public voidsetMediaSource(MediaSource mediaSource)
Clears the playlist, adds the specified MediaSource and resets the position to the default position.
| Parameters | |
|---|---|
MediaSource mediaSource |
The new |
setMediaSource
public voidsetMediaSource(MediaSource mediaSource, boolean resetPosition)
Clears the playlist and adds the specified MediaSource.
| Parameters | |
|---|---|
MediaSource mediaSource |
The new |
boolean resetPosition |
Whether the playback position should be reset to the default position. If false, playback will start from the position defined by |
setMediaSource
public voidsetMediaSource(MediaSource mediaSource, long startPositionMs)
Clears the playlist and adds the specified MediaSource.
| Parameters | |
|---|---|
MediaSource mediaSource |
The new |
long startPositionMs |
The position in milliseconds to start playback from. If |
setMediaSources
public voidsetMediaSources(List<MediaSource> mediaSources)
Clears the playlist, adds the specified MediaSources and resets the position to the default position.
| Parameters | |
|---|---|
List<MediaSource> mediaSources |
The new |
setMediaSources
public voidsetMediaSources(List<MediaSource> mediaSources, boolean resetPosition)
Clears the playlist and adds the specified MediaSources.
| Parameters | |
|---|---|
List<MediaSource> mediaSources |
The new |
boolean resetPosition |
Whether the playback position should be reset to the default position in the first |
setMediaSources
public voidsetMediaSources(
List<MediaSource> mediaSources,
int startMediaItemIndex,
long startPositionMs
)
Clears the playlist and adds the specified MediaSources.
| Parameters | |
|---|---|
List<MediaSource> mediaSources |
The new |
int startMediaItemIndex |
The media item index to start playback from. If |
long startPositionMs |
The position in milliseconds to start playback from. If |
setPauseAtEndOfMediaItems
public void setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems)Sets whether to pause playback at the end of each media item.
This means the player will pause at the end of each window in the current timeline. Listeners will be informed by a call to onPlayWhenReadyChanged with the reason PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM when this happens.
| Parameters | |
|---|---|
boolean pauseAtEndOfMediaItems |
Whether to pause playback at the end of each media item. |
setPlayWhenReady
public void setPlayWhenReady(boolean playWhenReady)Sets whether playback should proceed when getPlaybackState == STATE_READY.
If the player is already in the ready state then this method pauses and resumes playback.
This method must only be called if COMMAND_PLAY_PAUSE is available.
| Parameters | |
|---|---|
boolean playWhenReady |
Whether playback should proceed when ready. |
setPlaybackParameters
public voidsetPlaybackParameters(PlaybackParameters playbackParameters)
Attempts to set the playback parameters. Passing DEFAULT resets the player to the default, which means there is no speed or pitch adjustment.
Playback parameters changes may cause the player to buffer. onPlaybackParametersChanged will be called whenever the currently active playback parameters change.
This method must only be called if COMMAND_SET_SPEED_AND_PITCH is available.
| Parameters | |
|---|---|
PlaybackParameters playbackParameters |
The playback parameters. |
setPlaylistMetadata
public voidsetPlaylistMetadata(MediaMetadata mediaMetadata)
Sets the playlist MediaMetadata.
This method must only be called if COMMAND_SET_PLAYLIST_METADATA is available.
setPreferredAudioDevice
public voidsetPreferredAudioDevice(@Nullable AudioDeviceInfo audioDeviceInfo)
Sets the preferred audio device.
| Parameters | |
|---|---|
@Nullable AudioDeviceInfo audioDeviceInfo |
The preferred |
setPreloadConfiguration
public voidsetPreloadConfiguration(
ExoPlayer.PreloadConfiguration preloadConfiguration
)
Sets the preload configuration to configure playlist preloading.
| Parameters | |
|---|---|
ExoPlayer.PreloadConfiguration preloadConfiguration |
The preload configuration. |
setPriority
public voidsetPriority(@C.Priority int priority)
Sets the C.Priority for this player.
The priority may influence resource allocation between multiple players or other components running in the same app.
This priority is used for the PriorityTaskManager, if set.
| Parameters | |
|---|---|
@C.Priority int priority |
The |
setPriorityTaskManager
public voidsetPriorityTaskManager(
@Nullable PriorityTaskManager priorityTaskManager
)
Sets a PriorityTaskManager, or null to clear a previously set priority task manager.
The priority set via setPriority (or by default) will be set while the player is loading.
| Parameters | |
|---|---|
@Nullable PriorityTaskManager priorityTaskManager |
The |
setRepeatMode
public voidsetRepeatMode(@Player.RepeatMode int repeatMode)
Sets the RepeatMode to be used for playback.
This method must only be called if COMMAND_SET_REPEAT_MODE is available.
| Parameters | |
|---|---|
@Player.RepeatMode int repeatMode |
The repeat mode. |
setScrubbingModeEnabled
public void setScrubbingModeEnabled(boolean scrubbingModeEnabled)Sets whether to optimize the player for scrubbing (many frequent seeks).
The player may consume more resources in this mode, so it should only be used for short periods of time in response to user interaction (e.g. dragging on a progress bar UI element).
During scrubbing mode playback is suppressed with PLAYBACK_SUPPRESSION_REASON_SCRUBBING.
| Parameters | |
|---|---|
boolean scrubbingModeEnabled |
Whether scrubbing mode should be enabled. |
setScrubbingModeParameters
public voidsetScrubbingModeParameters(
ScrubbingModeParameters scrubbingModeParameters
)
Sets the parameters that control behavior in scrubbing mode.
setSeekBackIncrementMs
public void setSeekBackIncrementMs(long seekBackIncrementMs)Sets the seekBack increment.
| Parameters | |
|---|---|
long seekBackIncrementMs |
The seek back increment, in milliseconds. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If |
setSeekForwardIncrementMs
public void setSeekForwardIncrementMs(long seekForwardIncrementMs)Sets the seekForward increment.
| Parameters | |
|---|---|
long seekForwardIncrementMs |
The seek forward increment, in milliseconds. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If |
setSeekParameters
public voidsetSeekParameters(@Nullable SeekParameters seekParameters)
Sets the parameters that control how seek operations are performed.
| Parameters | |
|---|---|
@Nullable SeekParameters seekParameters |
The seek parameters, or |
setShuffleModeEnabled
public void setShuffleModeEnabled(boolean shuffleModeEnabled)Sets whether shuffling of media items is enabled.
This method must only be called if COMMAND_SET_SHUFFLE_MODE is available.
| Parameters | |
|---|---|
boolean shuffleModeEnabled |
Whether shuffling is enabled. |
setShuffleOrder
public voidsetShuffleOrder(ShuffleOrder shuffleOrder)
Sets the shuffle order.
The ShuffleOrder passed must have the same length as the current playlist (getMediaItemCount).
| Parameters | |
|---|---|
ShuffleOrder shuffleOrder |
The shuffle order. |
setSkipSilenceEnabled
public void setSkipSilenceEnabled(boolean skipSilenceEnabled)Sets whether skipping silences in the audio stream is enabled.
| Parameters | |
|---|---|
boolean skipSilenceEnabled |
Whether skipping silences in the audio stream is enabled. |
setTrackSelectionParameters
public voidsetTrackSelectionParameters(TrackSelectionParameters parameters)
Sets the parameters constraining the track selection.
Unsupported parameters will be silently ignored.
Use getTrackSelectionParameters to retrieve the current parameters. For example, the following snippet restricts video to SD whilst keep other track selection parameters unchanged:
player.setTrackSelectionParameters(
player.getTrackSelectionParameters()
.buildUpon()
.setMaxVideoSizeSd()
.build())This method must only be called if COMMAND_SET_TRACK_SELECTION_PARAMETERS is available.
setVideoChangeFrameRateStrategy
public voidsetVideoChangeFrameRateStrategy(
@C.VideoChangeFrameRateStrategy int videoChangeFrameRateStrategy
)
Sets a C.VideoChangeFrameRateStrategy that will be used by the player when provided with a video output Surface.
The strategy only applies if a MediaCodec-based video Renderer is enabled. Applications wishing to use CHANGE_FRAME_RATE_ALWAYS should set the mode to VIDEO_CHANGE_FRAME_RATE_STRATEGY_OFF to disable calls to setFrameRate from ExoPlayer, and should then call setFrameRate directly from application code.
| Parameters | |
|---|---|
@C.VideoChangeFrameRateStrategy int videoChangeFrameRateStrategy |
setVideoCodecParameters
public voidsetVideoCodecParameters(CodecParameters codecParameters)
Sets a collection of parameters on the underlying video codecs.
This method is asynchronous. The parameters will be applied to the video renderers on the playback thread.
The default MediaCodec based renderers only support this feature on API level 29 and above. If an underlying decoder does not support a parameter, it will be ignored.
| Parameters | |
|---|---|
CodecParameters codecParameters |
The |
setVideoEffects
public voidsetVideoEffects(List<Effect> videoEffects)
Sets a List of video effects that will be applied to each video frame.
If passing a surface to the player directly, the output resolution needs to be signaled by passing a message to the video renderer with type MSG_SET_VIDEO_OUTPUT_RESOLUTION after calling this method. For SurfaceView, TextureView and SurfaceHolder output this happens automatically.
Pass REDRAW to force the effect pipeline to redraw the effects immediately. To accurately interleave redraws, listen to onVideoFrameAboutToBeRendered events.
The following limitations exist for using video effects:
- The
androidx.media3:media3-effectmodule must be available on the runtime classpath.androidx.media3:media3-exoplayerdoes not explicitly depend on the effect module, so apps must make sure it's available themselves. It must be the same version as the rest of theandroidx.media3modules being used by the app. - This feature works only with the default
MediaCodecVideoRendererand not custom or extensionvideo renderers. - This feature does not work with
effectsthat update the frame timestamps. - This feature does not work with DRM-protected content.
- This method must be called at least once before calling
prepare(in order to set up the effects pipeline). The effects can be changed during playback by subsequent calls to this method afterprepare.
| Parameters | |
|---|---|
List<Effect> videoEffects |
The |
setVideoFrameMetadataListener
public voidsetVideoFrameMetadataListener(VideoFrameMetadataListener listener)
Sets a listener to receive video frame metadata events.
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.
| Parameters | |
|---|---|
VideoFrameMetadataListener listener |
The listener. |
setVideoScalingMode
public voidsetVideoScalingMode(@C.VideoScalingMode int videoScalingMode)
Sets the C.VideoScalingMode.
The scaling mode only applies if a MediaCodec-based video Renderer is enabled and if the output surface is owned by a SurfaceView.
| Parameters | |
|---|---|
@C.VideoScalingMode int videoScalingMode |
The |
setVideoSurface
public voidsetVideoSurface(@Nullable Surface surface)
Sets the 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 setVideoSurfaceView, setVideoTextureView or setVideoSurfaceHolder rather than this method, since passing the holder allows the player to track the lifecycle of the surface automatically.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
setVideoSurfaceHolder
public voidsetVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder)
Sets the SurfaceHolder that holds the Surface onto which video will be rendered. The player will track the lifecycle of the surface automatically.
The thread that calls the SurfaceHolder.Callback methods must be the thread associated with getApplicationLooper.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
@Nullable SurfaceHolder surfaceHolder |
The surface holder. |
setVideoSurfaceView
public voidsetVideoSurfaceView(@Nullable SurfaceView surfaceView)
Sets the SurfaceView onto which video will be rendered. The player will track the lifecycle of the surface automatically.
The thread that calls the SurfaceHolder.Callback methods must be the thread associated with getApplicationLooper.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
@Nullable SurfaceView surfaceView |
The surface view. |
setVideoTextureView
public voidsetVideoTextureView(@Nullable TextureView textureView)
Sets the TextureView onto which video will be rendered. The player will track the lifecycle of the surface automatically.
Consider using SurfaceView via setVideoSurfaceView instead of TextureView. SurfaceView generally causes lower battery consumption, and has better handling for HDR and secure content. See Choosing a surface type for more information.
The thread that calls the TextureView.SurfaceTextureListener methods must be the thread associated with getApplicationLooper.
This method must only be called if COMMAND_SET_VIDEO_SURFACE is available.
| Parameters | |
|---|---|
@Nullable TextureView textureView |
The texture view. |
setVirtualDeviceId
public void setVirtualDeviceId(int virtualDeviceId)Sets the virtual device id to be used for playback.
Note that the initial value is obtained from getDeviceId from the Context passed to Builder.
| Parameters | |
|---|---|
int virtualDeviceId |
The |
setVolume
public void setVolume(float volume)Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive.
This method must only be called if COMMAND_SET_VOLUME is available.
| Parameters | |
|---|---|
float volume |
Linear output gain to apply to all audio channels. |
setWakeMode
public voidsetWakeMode(@C.WakeMode int wakeMode)
Sets how the player should keep the device awake for playback when the screen is off.
Enabling this feature requires the WAKE_LOCK permission. It should be used together with a foreground android.app.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 (android.os.PowerManager.WakeLock / android.net.wifi.WifiManager.WifiLock) will be held whenever the player is in the STATE_READY or STATE_BUFFERING states with playWhenReady = true. The locks held depends on the specified C.WakeMode.
| Parameters | |
|---|---|
@C.WakeMode int wakeMode |
The |
stop
public void stop()Stops playback without resetting the playlist. Use pause rather than this method if the intention is to pause playback.
Calling this method will cause the playback state to transition to STATE_IDLE and the player will release the loaded media and resources required for playback. The player instance can still be used by calling prepare again, and release must still be called on the player if it's no longer required.
Calling this method does not clear the playlist, reset the playback position or the playback error.
This method must only be called if COMMAND_STOP is available.
unmute
public void unmute()If the audio volume is 0, sets the audio volume to a non-zero value decided by the Player to be the most appropriate.
This method must only be called if COMMAND_SET_VOLUME is available.
Protected methods
seekTo
protected voidseekTo(
int mediaItemIndex,
long positionMs,
@Player.Command int seekCommand,
boolean isRepeatingCurrentItem
)
Seeks to a position in the specified MediaItem.
| Parameters | |
|---|---|
int mediaItemIndex |
The index of the |
long positionMs |
The seek position in the specified |
@Player.Command int seekCommand |
The |
boolean isRepeatingCurrentItem |
Whether this seeks repeats the current item. |