ExoPlayer
public interface ExoPlayer extends Player
SimpleExoPlayer |
This class is deprecated. Use |
StubExoPlayer |
An abstract |
An extensible media player that plays MediaSources. Instances can be obtained from Builder.
Player components
ExoPlayer is designed to make few assumptions about (and hence impose few restrictions on) the type of the media being played, how and where it is stored, and how it is rendered. Rather than implementing the loading and rendering of media directly, ExoPlayer implementations delegate this work to components that are injected when a player is created or when it's prepared for playback. Components common to all ExoPlayer implementations are:
MediaSourcesthat define the media to be played, load the media, and from which the loaded media can be read. MediaSources are created fromMediaItemsby theMediaSource.Factoryinjected into the playerBuilder, or can be added directly by methods likesetMediaSource. The library provides aDefaultMediaSourceFactoryfor progressive media files, DASH, SmoothStreaming and HLS, which also includes functionality for side-loading subtitle files and clipping media.Renderers that render individual components of the media. The library provides default implementations for common media types (MediaCodecVideoRenderer,MediaCodecAudioRenderer,TextRendererandMetadataRenderer). A Renderer consumes media from the MediaSource being played. Renderers are injected when the player is created. The number of renderers and their respective track types can be obtained by callinggetRendererCountandgetRendererType.- A
TrackSelectorthat selects tracks provided by the MediaSource to be consumed by each of the available Renderers. The library provides a default implementation (DefaultTrackSelector) suitable for most use cases. A TrackSelector is injected when the player is created. - A
LoadControlthat controls when the MediaSource buffers more media, and how much media is buffered. The library provides a default implementation (DefaultLoadControl) suitable for most use cases. A LoadControl is injected when the player is created.
An ExoPlayer can be built using the default components provided by the library, but may also be built using custom implementations if non-standard behaviors are required. For example a custom LoadControl could be injected to change the player's buffering strategy, or a custom Renderer could be injected to add support for a video codec not supported natively by Android.
The concept of injecting components that implement pieces of player functionality is present throughout the library. The default component implementations listed above delegate work to further injected components. This allows many sub-components to be individually replaced with custom implementations. For example the default MediaSource implementations require one or more DataSource factories to be injected via their constructors. By providing a custom factory it's possible to load data from a non-standard source, or through a different network stack.
Threading model
The figure below shows ExoPlayer's threading model.
- ExoPlayer instances must be accessed from a single application thread unless indicated otherwise. For the vast majority of cases this should be the application's main thread. Using the application's main thread is also a requirement when using ExoPlayer's UI components or the IMA extension. The thread on which an ExoPlayer instance must be accessed can be explicitly specified by passing a
Looperwhen creating the player. If noLooperis specified, then theLooperof the thread that the player is created on is used, or if that thread does not have aLooper, theLooperof the application's main thread is used. In all cases theLooperof the thread from which the player must be accessed can be queried usinggetApplicationLooper. - Registered listeners are called on the thread associated with
getApplicationLooper. Note that this means registered listeners are called on the same thread which must be used to access the player. - An internal playback thread is responsible for playback. Injected player components such as Renderers, MediaSources, TrackSelectors and LoadControls are called by the player on this thread.
- When the application performs an operation on the player, for example a seek, a message is delivered to the internal playback thread via a message queue. The internal playback thread consumes messages from the queue and performs the corresponding operations. Similarly, when a playback event occurs on the internal playback thread, a message is delivered to the application thread via a second message queue. The application thread consumes messages from the queue, updating the application visible state and calling corresponding listener methods.
- Injected player components may use additional background threads. For example a MediaSource may use background threads to load data. These are implementation specific.
Summary
Nested types |
|---|
@UnstableApiA listener for audio offload events. |
public final class ExoPlayer.BuilderA builder for |
@UnstableApiConfiguration options for preloading playlist items. |
Constants |
|
|---|---|
default static final long |
The default timeout for detaching a surface from the player, in milliseconds. |
default static final long |
The default timeout for calls to |
default static final int |
The default timeout for detecting whether playback is stuck buffering, in milliseconds. |
default static final int |
The default timeout for detecting whether playback is stuck playing, in milliseconds. |
default static final int |
The default timeout for detecting whether playback is stuck playing but not ending, in milliseconds. |
default static final int |
The default timeout for detecting whether playback is stuck in a suppressed state, in milliseconds. |
Public methods |
|
|---|---|
abstract void |
addAnalyticsListener(AnalyticsListener listener)Adds an |
abstract void |
@UnstableApiAdds a listener for audio codec parameter changes. |
abstract void |
Adds a listener to receive audio offload events. |
abstract void |
@UnstableApiAdds a media source to the end of the playlist. |
abstract void |
@UnstableApiAdds a media source at the given index of the playlist. |
abstract void |
@UnstableApiAdds a list of media sources to the end of the playlist. |
abstract void |
@UnstableApiAdds a list of media sources at the given index of the playlist. |
abstract void |
@UnstableApiAdds a listener for video codec parameter changes. |
abstract void |
Detaches any previously attached auxiliary audio effect from the underlying audio track. |
abstract void |
Clears the listener which receives camera motion events if it matches the one passed. |
abstract void |
Clears the listener which receives video frame metadata events if it matches the one passed. |
abstract PlayerMessage |
Creates a message that can be sent to a |
abstract AnalyticsCollector |
Returns the |
abstract @Nullable DecoderCounters |
Returns |
abstract @Nullable Format |
Returns the audio format currently being played, or null if no audio is being played. |
abstract Clock |
Returns the |
abstract TrackGroupArray |
This method is deprecated. Use |
abstract TrackSelectionArray |
This method is deprecated. Use |
abstract boolean |
Returns whether the player pauses playback at the end of each media item. |
abstract Looper |
Returns the |
abstract @Nullable ExoPlaybackException |
Equivalent to |
abstract ExoPlayer.PreloadConfiguration |
Returns the |
abstract Renderer |
@UnstableApiReturns the renderer at the given index. |
abstract int |
Returns the number of renderers. |
abstract int |
@UnstableApiReturns the track type that the renderer at a given index handles. |
abstract ScrubbingModeParameters |
Gets the parameters that control behavior in |
abstract @Nullable Renderer |
@UnstableApiReturns the secondary renderer at the given index. |
abstract SeekParameters |
Returns the currently active |
abstract ShuffleOrder |
Returns the shuffle order. |
abstract boolean |
Returns whether skipping silences in the audio stream is enabled. |
abstract @Nullable TrackSelector |
Returns the track selector that this player uses, or null if track selection is not supported. |
abstract int |
Returns the |
abstract @Nullable DecoderCounters |
Returns |
abstract @Nullable Format |
Returns the video format currently being played, or null if no video is being played. |
abstract int |
Returns the |
abstract boolean |
Returns whether |
abstract boolean |
Returns whether the player is optimized for scrubbing (many frequent seeks). |
abstract boolean |
Returns whether the player has paused its main loop to save power in offload scheduling mode. |
abstract boolean |
Returns whether tunneling is enabled for the currently selected tracks. |
abstract void |
@UnstableApiThis method is deprecated. Use |
abstract void |
@UnstableApiThis method is deprecated. Use |
abstract void |
release()Releases the player. |
abstract void |
removeAnalyticsListener(AnalyticsListener listener)Removes an |
abstract void |
Removes a listener for audio codec parameter changes. |
abstract void |
Removes a listener of audio offload events. |
abstract void |
Removes a listener for video codec parameter changes. |
abstract void |
replaceMediaItem(int index, MediaItem mediaItem)Replaces the media item at the given index of the playlist. |
abstract void |
replaceMediaItems(Replaces the media items at the given range of the playlist. |
abstract void |
@UnstableApiSets a collection of parameters on the underlying audio codecs. |
abstract void |
@UnstableApiSets the ID of the audio session to attach to the underlying |
abstract void |
@UnstableApiSets information on an auxiliary audio effect to attach to the underlying audio track. |
abstract void |
Sets a listener of camera motion events. |
abstract void |
@UnstableApiSets whether the player is allowed to keep holding limited resources such as video decoders, even when in the idle state. |
abstract void |
setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy)Sets whether the player should pause automatically when audio is rerouted from a headset to device speakers. |
abstract void |
@UnstableApiSets the |
abstract void |
@UnstableApiSets the maximum position for which |
abstract void |
@UnstableApiClears the playlist, adds the specified |
abstract void |
@UnstableApiClears the playlist and adds the specified |
abstract void |
@UnstableApiClears the playlist and adds the specified |
abstract void |
@UnstableApiClears the playlist, adds the specified |
abstract void |
@UnstableApiClears the playlist and adds the specified |
abstract void |
@UnstableApiClears the playlist and adds the specified |
abstract void |
@UnstableApiSets whether to pause playback at the end of each media item. |
abstract void |
@UnstableApiSets the preferred audio device. |
abstract void |
@UnstableApiSets the |
abstract void |
@UnstableApiSets the |
abstract void |
@UnstableApiSets a |
abstract void |
@UnstableApiSets whether to optimize the player for scrubbing (many frequent seeks). |
abstract void |
@UnstableApiSets the parameters that control behavior in |
abstract void |
@UnstableApiSets the |
abstract void |
@UnstableApiSets the |
abstract void |
@UnstableApiSets the parameters that control how seek operations are performed. |
abstract void |
@UnstableApiSets the shuffle order. |
abstract void |
@UnstableApiSets whether skipping silences in the audio stream is enabled. |
abstract void |
@UnstableApiSets a |
abstract void |
@UnstableApiSets a collection of parameters on the underlying video codecs. |
abstract void |
@UnstableApiSets a |
abstract void |
Sets a listener to receive video frame metadata events. |
abstract void |
@UnstableApiSets the |
abstract void |
@UnstableApiSets the virtual device id to be used for playback. |
abstract void |
setWakeMode(@C.WakeMode int wakeMode)Sets how the player should keep the device awake for playback when the screen is off. |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
DEFAULT_DETACH_SURFACE_TIMEOUT_MS
@UnstableApi
default static final long DEFAULT_DETACH_SURFACE_TIMEOUT_MS = 2000
The default timeout for detaching a surface from the player, in milliseconds.
DEFAULT_RELEASE_TIMEOUT_MS
@UnstableApi
default static final long DEFAULT_RELEASE_TIMEOUT_MS = 500
The default timeout for calls to release and setForegroundMode, in milliseconds.
DEFAULT_STUCK_BUFFERING_DETECTION_TIMEOUT_MS
@UnstableApi
default static final int DEFAULT_STUCK_BUFFERING_DETECTION_TIMEOUT_MS = 600000
The default timeout for detecting whether playback is stuck buffering, in milliseconds.
DEFAULT_STUCK_PLAYING_DETECTION_TIMEOUT_MS
@UnstableApi
default static final int DEFAULT_STUCK_PLAYING_DETECTION_TIMEOUT_MS
The default timeout for detecting whether playback is stuck playing, in milliseconds.
DEFAULT_STUCK_PLAYING_NOT_ENDING_TIMEOUT_MS
@UnstableApi
default static final int DEFAULT_STUCK_PLAYING_NOT_ENDING_TIMEOUT_MS = 60000
The default timeout for detecting whether playback is stuck playing but not ending, in milliseconds.
DEFAULT_STUCK_SUPPRESSED_DETECTION_TIMEOUT_MS
@UnstableApi
default static final int DEFAULT_STUCK_SUPPRESSED_DETECTION_TIMEOUT_MS = 600000
The default timeout for detecting whether playback is stuck in a suppressed state, in milliseconds.
Public methods
addAnalyticsListener
abstract void addAnalyticsListener(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
@UnstableApi
abstract void addAudioCodecParametersChangeListener(
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
@UnstableApi
abstract void addAudioOffloadListener(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. |
addMediaSource
@UnstableApi
abstract void addMediaSource(MediaSource mediaSource)
Adds a media source to the end of the playlist.
| Parameters | |
|---|---|
MediaSource mediaSource |
The |
addMediaSource
@UnstableApi
abstract void addMediaSource(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
@UnstableApi
abstract void addMediaSources(List<MediaSource> mediaSources)
Adds a list of media sources to the end of the playlist.
| Parameters | |
|---|---|
List<MediaSource> mediaSources |
The |
addMediaSources
@UnstableApi
abstract void addMediaSources(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
@UnstableApi
abstract void addVideoCodecParametersChangeListener(
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
@UnstableApi
abstract void clearAuxEffectInfo()
Detaches any previously attached auxiliary audio effect from the underlying audio track.
clearCameraMotionListener
@UnstableApi
abstract void clearCameraMotionListener(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
@UnstableApi
abstract void clearVideoFrameMetadataListener(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. |
createMessage
@UnstableApi
abstract PlayerMessage createMessage(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.
getAnalyticsCollector
@UnstableApi
abstract AnalyticsCollector getAnalyticsCollector()
Returns the AnalyticsCollector used for collecting analytics events.
getAudioDecoderCounters
@UnstableApi
abstract @Nullable DecoderCounters getAudioDecoderCounters()
Returns DecoderCounters for audio, or null if no audio is being played.
getAudioFormat
@UnstableApi
abstract @Nullable Format getAudioFormat()
Returns the audio format currently being played, or null if no audio is being played.
getClock
@UnstableApi
abstract Clock getClock()
Returns the Clock used for playback.
This method can be called from any thread.
getCurrentTrackGroups
@UnstableApi
abstract TrackGroupArraygetCurrentTrackGroups()
Returns the available track groups.
| See also | |
|---|---|
onTracksChanged |
getCurrentTrackSelections
@UnstableApi
abstract TrackSelectionArraygetCurrentTrackSelections()
Returns the current track selections for each renderer, which may include null elements if some renderers do not have any selected tracks.
| See also | |
|---|---|
onTracksChanged |
getPauseAtEndOfMediaItems
@UnstableApi
abstract boolean getPauseAtEndOfMediaItems()
Returns whether the player pauses playback at the end of each media item.
| See also | |
|---|---|
setPauseAtEndOfMediaItems |
getPlaybackLooper
@UnstableApi
abstract Looper getPlaybackLooper()
Returns the Looper associated with the playback thread.
This method may be called from any thread.
getPlayerError
abstract @Nullable ExoPlaybackException getPlayerError()
Equivalent to getPlayerError, except the exception is guaranteed to be an ExoPlaybackException.
getPreloadConfiguration
@UnstableApi
abstract ExoPlayer.PreloadConfiguration getPreloadConfiguration()
Returns the preload configuration.
getRenderer
@UnstableApi
abstract Renderer getRenderer(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
@UnstableApi
@C.TrackType
abstract int getRendererType(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 |
getScrubbingModeParameters
@UnstableApi
abstract ScrubbingModeParameters getScrubbingModeParameters()
Gets the parameters that control behavior in scrubbing mode.
getSecondaryRenderer
@UnstableApi
abstract @Nullable Renderer getSecondaryRenderer(int index)
Returns the secondary renderer at the given index.
| Parameters | |
|---|---|
int index |
The index of the secondary renderer. |
getSeekParameters
@UnstableApi
abstract SeekParameters getSeekParameters()
Returns the currently active SeekParameters of the player.
getShuffleOrder
@UnstableApi
abstract ShuffleOrder getShuffleOrder()
Returns the shuffle order.
The ShuffleOrder returned will have the same length as the current playlist (getMediaItemCount).
getSkipSilenceEnabled
@UnstableApi
abstract boolean getSkipSilenceEnabled()
Returns whether skipping silences in the audio stream is enabled.
| See also | |
|---|---|
onSkipSilenceEnabledChanged |
getTrackSelector
@UnstableApi
abstract @Nullable TrackSelector getTrackSelector()
Returns the track selector that this player uses, or null if track selection is not supported.
getVideoChangeFrameRateStrategy
@UnstableApi
@C.VideoChangeFrameRateStrategy
abstract int getVideoChangeFrameRateStrategy()
Returns the C.VideoChangeFrameRateStrategy.
getVideoDecoderCounters
@UnstableApi
abstract @Nullable DecoderCounters getVideoDecoderCounters()
Returns DecoderCounters for video, or null if no video is being played.
getVideoFormat
@UnstableApi
abstract @Nullable Format getVideoFormat()
Returns the video format currently being played, or null if no video is being played.
getVideoScalingMode
@UnstableApi
@C.VideoScalingMode
abstract int getVideoScalingMode()
Returns the C.VideoScalingMode.
isReleased
@UnstableApi
abstract boolean isReleased()
Returns whether release has been called on the player.
This method is allowed to be called after release.
isScrubbingModeEnabled
@UnstableApi
abstract boolean isScrubbingModeEnabled()
Returns whether the player is optimized for scrubbing (many frequent seeks).
isSleepingForOffload
@UnstableApi
abstract 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
@UnstableApi
abstract boolean isTunnelingEnabled()
Returns whether tunneling is enabled for the currently selected tracks.
| See also | |
|---|---|
onTracksChanged |
prepare
@UnstableApi
abstract voidprepare(
MediaSource mediaSource,
boolean resetPosition,
boolean resetState
)
release
abstract 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 * #getAvailableCommands() available.
The exception to the above rule is isReleased which can be called on a released player.
removeAnalyticsListener
abstract void removeAnalyticsListener(AnalyticsListener listener)
Removes an AnalyticsListener.
| Parameters | |
|---|---|
AnalyticsListener listener |
The listener to be removed. |
removeAudioCodecParametersChangeListener
@UnstableApi
abstract void removeAudioCodecParametersChangeListener(
CodecParametersChangeListener listener
)
Removes a listener for audio codec parameter changes.
| Parameters | |
|---|---|
CodecParametersChangeListener listener |
The |
removeAudioOffloadListener
@UnstableApi
abstract void removeAudioOffloadListener(ExoPlayer.AudioOffloadListener listener)
Removes a listener of audio offload events.
| Parameters | |
|---|---|
ExoPlayer.AudioOffloadListener listener |
The listener to unregister. |
removeVideoCodecParametersChangeListener
@UnstableApi
abstract void removeVideoCodecParametersChangeListener(
CodecParametersChangeListener listener
)
Removes a listener for video codec parameter changes.
| Parameters | |
|---|---|
CodecParametersChangeListener listener |
The |
replaceMediaItem
abstract void replaceMediaItem(int index, MediaItem mediaItem)
Replaces the media item at the given index 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 * #getAvailableCommands() available.
ExoPlayer will keep the existing MediaSource for this MediaItem if supported by the MediaSource. If the current item is replaced, this will also not interrupt the ongoing playback.
replaceMediaItems
abstract void replaceMediaItems(
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 * #getAvailableCommands() 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.
ExoPlayer will keep the existing MediaSource instances for the new MediaItems if supported by all of these MediaSource instances. If the current item is replaced, this will also not interrupt the ongoing playback.
setAudioCodecParameters
@UnstableApi
abstract void setAudioCodecParameters(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
@UnstableApi
abstract 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
@UnstableApi
abstract void setAuxEffectInfo(AuxEffectInfo auxEffectInfo)
Sets information on an auxiliary audio effect to attach to the underlying audio track.
setCameraMotionListener
@UnstableApi
abstract void setCameraMotionListener(CameraMotionListener listener)
Sets a listener of camera motion events.
| Parameters | |
|---|---|
CameraMotionListener listener |
The listener. |
setForegroundMode
@UnstableApi
abstract 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
abstract 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
@UnstableApi
abstract void setImageOutput(@Nullable ImageOutput imageOutput)
Sets the ImageOutput where rendered images will be forwarded.
| Parameters | |
|---|---|
@Nullable ImageOutput imageOutput |
The |
setMaxSeekToPreviousPositionMs
@UnstableApi
abstract void setMaxSeekToPreviousPositionMs(
@IntRange(from = 0) long maxSeekToPreviousPositionMs
)
Sets the maximum position for which seekToPrevious seeks to the previous MediaItem.
| Parameters | |
|---|---|
@IntRange(from = 0) long maxSeekToPreviousPositionMs |
The maximum position, in milliseconds. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If |
setMediaSource
@UnstableApi
abstract void setMediaSource(MediaSource mediaSource)
Clears the playlist, adds the specified MediaSource and resets the position to the default position.
| Parameters | |
|---|---|
MediaSource mediaSource |
The new |
setMediaSource
@UnstableApi
abstract void setMediaSource(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
@UnstableApi
abstract void setMediaSource(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
@UnstableApi
abstract void setMediaSources(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
@UnstableApi
abstract void setMediaSources(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
@UnstableApi
abstract void setMediaSources(
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
@UnstableApi
abstract 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. |
setPreferredAudioDevice
@UnstableApi
abstract void setPreferredAudioDevice(@Nullable AudioDeviceInfo audioDeviceInfo)
Sets the preferred audio device.
| Parameters | |
|---|---|
@Nullable AudioDeviceInfo audioDeviceInfo |
The preferred |
setPreloadConfiguration
@UnstableApi
abstract void setPreloadConfiguration(
ExoPlayer.PreloadConfiguration preloadConfiguration
)
Sets the preload configuration to configure playlist preloading.
| Parameters | |
|---|---|
ExoPlayer.PreloadConfiguration preloadConfiguration |
The preload configuration. |
setPriority
@UnstableApi
abstract void setPriority(@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
@UnstableApi
abstract void setPriorityTaskManager(
@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 |
setScrubbingModeEnabled
@UnstableApi
abstract 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
@UnstableApi
abstract void setScrubbingModeParameters(
ScrubbingModeParameters scrubbingModeParameters
)
Sets the parameters that control behavior in scrubbing mode.
setSeekBackIncrementMs
@UnstableApi
abstract void setSeekBackIncrementMs(@IntRange(from = 1) long seekBackIncrementMs)
Sets the seekBack increment.
| Parameters | |
|---|---|
@IntRange(from = 1) long seekBackIncrementMs |
The seek back increment, in milliseconds. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If |
setSeekForwardIncrementMs
@UnstableApi
abstract void setSeekForwardIncrementMs(@IntRange(from = 1) long seekForwardIncrementMs)
Sets the seekForward increment.
| Parameters | |
|---|---|
@IntRange(from = 1) long seekForwardIncrementMs |
The seek forward increment, in milliseconds. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
If |
setSeekParameters
@UnstableApi
abstract void setSeekParameters(@Nullable SeekParameters seekParameters)
Sets the parameters that control how seek operations are performed.
| Parameters | |
|---|---|
@Nullable SeekParameters seekParameters |
The seek parameters, or |
setShuffleOrder
@UnstableApi
abstract void setShuffleOrder(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
@UnstableApi
abstract 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. |
setVideoChangeFrameRateStrategy
@UnstableApi
abstract void setVideoChangeFrameRateStrategy(
@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
@UnstableApi
abstract void setVideoCodecParameters(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
@UnstableApi
abstract void setVideoEffects(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
@UnstableApi
abstract void setVideoFrameMetadataListener(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
@UnstableApi
abstract void setVideoScalingMode(@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 |
setVirtualDeviceId
@UnstableApi
abstract 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 |
setWakeMode
abstract void setWakeMode(@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 |