SimpleExoPlayer


@UnstableApi
public class SimpleExoPlayer extends BasePlayer implements ExoPlayer


Summary

Nested types

public final class SimpleExoPlayer.Builder

This class is deprecated.

Use ExoPlayer.Builder instead.

Protected constructors

SimpleExoPlayer(
    Context context,
    RenderersFactory renderersFactory,
    TrackSelector trackSelector,
    MediaSource.Factory mediaSourceFactory,
    LoadControl loadControl,
    BandwidthMeter bandwidthMeter,
    AnalyticsCollector analyticsCollector,
    boolean useLazyPreparation,
    Clock clock,
    Looper applicationLooper
)

This method is deprecated.

Use the ExoPlayer.Builder.

Public methods

void

Adds an AnalyticsListener to receive analytics events.

void

Adds a listener to receive audio offload events.

void

Registers a listener to receive all events from the player.

void
addMediaItems(int index, List<MediaItem> mediaItems)

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
addMediaSource(int index, MediaSource mediaSource)

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
addMediaSources(int index, List<MediaSource> mediaSources)

Adds a list of media sources at the given index of the playlist.

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 Surface, SurfaceHolder, SurfaceView or TextureView currently set on the player.

void

Clears the Surface onto which video is being rendered if it matches the one passed.

void

Clears the SurfaceHolder that holds the Surface onto which video is being rendered if it matches the one passed.

void

Clears the SurfaceView onto which video is being rendered if it matches the one passed.

void

Clears the TextureView onto which video is being rendered if it matches the one passed.

PlayerMessage

Creates a message that can be sent to a PlayerMessage.Target.

void

This method is deprecated.

Use decreaseDeviceVolume instead.

void

Decreases the volume of the device.

AnalyticsCollector

Returns the AnalyticsCollector used for collecting analytics events.

Looper

Returns the Looper associated with the application thread that's used to access the player and on which player events are received.

AudioAttributes

Returns the attributes for audio playback.

@Nullable DecoderCounters

Returns DecoderCounters for audio, or null if no audio is being played.

@Nullable Format

Returns the audio format currently being played, or null if no audio is being played.

int

Returns the audio session identifier, or AUDIO_SESSION_ID_UNSET if not set.

Player.Commands

Returns the player's currently available Commands.

long

Returns an estimate of the position in the current content or ad up to which data is buffered, in milliseconds.

Clock

Returns the Clock used for playback.

long

If isPlayingAd returns true, returns an estimate of the content position in the current content up to which data is buffered, in milliseconds.

long

If isPlayingAd returns true, returns the content position that will be played once all ads in the ad group have finished playing, in milliseconds.

int

If isPlayingAd returns true, returns the index of the ad group in the period currently being played.

int

If isPlayingAd returns true, returns the index of the ad in its ad group.

CueGroup

Returns the current CueGroup.

int

Returns the index of the current MediaItem in the timeline, or the prospective index if the current timeline is empty.

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 current timeline is empty.

Timeline

Returns the current Timeline.

TrackGroupArray

This method is deprecated.

Use getCurrentTracks.

TrackSelectionArray

This method is deprecated.

Use getCurrentTracks.

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 TIME_UNSET if the duration is not known.

long

Returns the maximum position for which seekToPrevious seeks to the previous , in milliseconds.

MediaMetadata

Returns the current combined MediaMetadata, or EMPTY if not supported.

boolean

Returns whether the player pauses playback at the end of each media item.

boolean

Whether playback will proceed when getPlaybackState == STATE_READY.

Looper

Returns the Looper associated with the playback thread.

PlaybackParameters

Returns the currently active playback parameters.

int

Returns the current playback state of the player.

int

Returns the reason why playback is suppressed even though getPlayWhenReady is true, or PLAYBACK_SUPPRESSION_REASON_NONE if playback is not suppressed.

@Nullable ExoPlaybackException

Returns the error that caused playback to fail.

MediaMetadata

Returns the playlist MediaMetadata, as set by setPlaylistMetadata, or EMPTY if not supported.

ExoPlayer.PreloadConfiguration

Returns the preload configuration.

Renderer
getRenderer(int index)

Returns the renderer at the given index.

int

Returns the number of renderers.

int

Returns the track type that the renderer at a given index handles.

int

Returns the current RepeatMode used for playback.

ScrubbingModeParameters

Gets the parameters that control behavior in scrubbing mode.

long

Returns the seekBack increment.

long

Returns the seekForward increment.

SeekParameters

Returns the currently active SeekParameters of the player.

boolean

Returns whether shuffling of media items is enabled.

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 C.VideoChangeFrameRateStrategy.

@Nullable DecoderCounters

Returns DecoderCounters for video, or null if no video is being played.

@Nullable Format

Returns the video format currently being played, or null if no video is being played.

int

Returns the C.VideoScalingMode.

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 increaseDeviceVolume instead.

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 release has been called on the player.

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
moveMediaItems(int fromIndex, int toIndex, int newIndex)

Moves the media item range to the new index.

void

Prepares the player.

void
prepare(MediaSource mediaSource)

This method is deprecated.

Use setMediaSource and prepare instead.

void
prepare(
    MediaSource mediaSource,
    boolean resetPosition,
    boolean resetState
)

This method is deprecated.

Use setMediaSource and prepare instead.

void

Releases the player.

void

Removes an AnalyticsListener.

void

Removes a listener of audio offload events.

void

Unregister a listener registered through addListener.

void
removeMediaItems(int fromIndex, int toIndex)

Removes a range of media items from the playlist.

void
replaceMediaItems(
    int fromIndex,
    int toIndex,
    List<MediaItem> mediaItems
)

Replaces the media items at the given range of the playlist.

void
setAudioAttributes(
    AudioAttributes audioAttributes,
    boolean handleAudioFocus
)

Sets the attributes for audio playback, used by the underlying audio track.

void
setAudioSessionId(int audioSessionId)

Sets the ID of the audio session to attach to the underlying android.media.AudioTrack.

void

Sets information on an auxiliary audio effect to attach to the underlying audio track.

void

Sets a listener of camera motion events.

void
setDeviceMuted(boolean muted)

This method is deprecated.

Use setDeviceMuted instead.

void
setDeviceMuted(boolean muted, @C.VolumeFlags int flags)

Sets the mute state of the device.

void
setDeviceVolume(int volume)

This method is deprecated.

Use setDeviceVolume instead.

void
setDeviceVolume(int volume, @C.VolumeFlags int flags)

Sets the volume of the device with volume flags.

void
setForegroundMode(boolean foregroundMode)

Sets whether the player is allowed to keep holding limited resources such as video decoders, even when in the idle state.

void
setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy)

Sets whether the player should pause automatically when audio is rerouted from a headset to device speakers.

void

Sets the ImageOutput where rendered images will be forwarded.

void
setMediaItems(List<MediaItem> mediaItems, boolean resetPosition)

Clears the playlist and adds the specified media items.

void
setMediaItems(
    List<MediaItem> mediaItems,
    int startIndex,
    long startPositionMs
)

Clears the playlist and adds the specified media items.

void

Clears the playlist, adds the specified MediaSource and resets the position to the default position.

void
setMediaSource(MediaSource mediaSource, boolean resetPosition)

Clears the playlist and adds the specified MediaSource.

void
setMediaSource(MediaSource mediaSource, long startPositionMs)

Clears the playlist and adds the specified MediaSource.

void

Clears the playlist, adds the specified MediaSources and resets the position to the default position.

void
setMediaSources(List<MediaSource> mediaSources, boolean resetPosition)

Clears the playlist and adds the specified MediaSources.

void
setMediaSources(
    List<MediaSource> mediaSources,
    int startMediaItemIndex,
    long startPositionMs
)

Clears the playlist and adds the specified MediaSources.

void
setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems)

Sets whether to pause playback at the end of each media item.

void
setPlayWhenReady(boolean playWhenReady)

Sets whether playback should proceed when getPlaybackState == STATE_READY.

void

Attempts to set the playback parameters.

void

Sets the playlist MediaMetadata.

void

Sets the preferred audio device.

void

Sets the preload configuration to configure playlist preloading.

void
setPriority(@C.Priority int priority)

Sets the C.Priority for this player.

void
setPriorityTaskManager(
    @Nullable PriorityTaskManager priorityTaskManager
)

Sets a PriorityTaskManager, or null to clear a previously set priority task manager.

void

Sets the RepeatMode to be used for playback.

void
setScrubbingModeEnabled(boolean scrubbingModeEnabled)

Sets whether to optimize the player for scrubbing (many frequent seeks).

void
setScrubbingModeParameters(
    ScrubbingModeParameters scrubbingModeParameters
)

Sets the parameters that control behavior in scrubbing mode.

void

Sets the parameters that control how seek operations are performed.

void
setShuffleModeEnabled(boolean shuffleModeEnabled)

Sets whether shuffling of media items is enabled.

void

Sets the shuffle order.

void
setSkipSilenceEnabled(boolean skipSilenceEnabled)

Sets whether skipping silences in the audio stream is enabled.

void

Sets the parameters constraining the track selection.

void
setVideoChangeFrameRateStrategy(
    @C.VideoChangeFrameRateStrategy int videoChangeFrameRateStrategy
)

Sets a C.VideoChangeFrameRateStrategy that will be used by the player when provided with a video output Surface.

void
setVideoEffects(List<Effect> videoEffects)

Sets a List of video effects that will be applied to each video frame.

void

Sets a listener to receive video frame metadata events.

void
setVideoScalingMode(@C.VideoScalingMode int videoScalingMode)

Sets the C.VideoScalingMode.

void

Sets the Surface onto which video will be rendered.

void

Sets the SurfaceHolder that holds the Surface onto which video will be rendered.

void

Sets the SurfaceView onto which video will be rendered.

void

Sets the TextureView onto which video will be rendered.

void
setVolume(float volume)

Sets the audio volume, valid values are between 0 (silence) and 1 (unity gain, signal unchanged), inclusive.

void
setWakeMode(@C.WakeMode int wakeMode)

Sets how the player should keep the device awake for playback when the screen is off.

void

Stops playback without resetting the playlist.

Protected methods

void
seekTo(
    int mediaItemIndex,
    long positionMs,
    @Player.Command int seekCommand,
    boolean isRepeatingCurrentItem
)

Seeks to a position in the specified MediaItem.

Inherited Constants

From androidx.media3.exoplayer.ExoPlayer
static final long

The default timeout for detaching a surface from the player, in milliseconds.

static final long

The default timeout for calls to release and setForegroundMode, in milliseconds.

From androidx.media3.common.Player
static final int

This field is deprecated.

Use COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS instead.

static final int

Command to increase and decrease the device volume and mute it with volume flags.

static final int

Command to change the media items in the playlist.

static final int

Command to get the player current AudioAttributes.

static final int

Command to get information about the currently playing MediaItem.

static final int

Command to get the device volume and whether it is muted.

static final int

This field is deprecated.

Use COMMAND_GET_METADATA instead.

static final int

Command to get metadata related to the playlist and current MediaItem.

static final int

Command to get the text that should currently be displayed by the player.

static final int

Command to get the information about the current timeline.

static final int

Command to get details of the current track selection.

static final int

Command to get the player volume.

static final int

Represents an invalid Command.

static final int

Command to start, pause or resume playback.

static final int

Command to prepare the player.

static final int

Command to release the player.

static final int

Command to seek back by a fixed increment inside the current MediaItem.

static final int

Command to seek forward by a fixed increment inside the current MediaItem.

static final int