public static final class SimpleExoPlayer.Builder extends Object
SimpleExoPlayer
instances.
See Builder(Context)
for the list of default values.
Constructor | Description |
---|---|
Builder(Context context) |
Creates a builder.
|
Builder(Context context,
ExtractorsFactory extractorsFactory) |
Creates a builder with a custom
ExtractorsFactory . |
Builder(Context context,
RenderersFactory renderersFactory) |
Creates a builder with a custom
RenderersFactory . |
Builder(Context context,
RenderersFactory renderersFactory,
ExtractorsFactory extractorsFactory) |
Creates a builder with a custom
RenderersFactory and ExtractorsFactory . |
Builder(Context context,
RenderersFactory renderersFactory,
TrackSelector trackSelector,
MediaSourceFactory mediaSourceFactory,
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
AnalyticsCollector analyticsCollector) |
Creates a builder with the specified custom components.
|
Modifier and Type | Method | Description |
---|---|---|
SimpleExoPlayer |
build() |
Builds a
SimpleExoPlayer instance. |
SimpleExoPlayer.Builder |
setAnalyticsCollector(AnalyticsCollector analyticsCollector) |
Sets the
AnalyticsCollector that will collect and forward all player events. |
SimpleExoPlayer.Builder |
setAudioAttributes(AudioAttributes audioAttributes,
boolean handleAudioFocus) |
Sets
AudioAttributes that will be used by the player and whether to handle audio
focus. |
SimpleExoPlayer.Builder |
setBandwidthMeter(BandwidthMeter bandwidthMeter) |
Sets the
BandwidthMeter that will be used by the player. |
SimpleExoPlayer.Builder |
setClock(Clock clock) |
Sets the
Clock that will be used by the player. |
SimpleExoPlayer.Builder |
setDetachSurfaceTimeoutMs(long detachSurfaceTimeoutMs) |
Sets a timeout for detaching a surface from the player.
|
SimpleExoPlayer.Builder |
setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) |
Sets whether the player should pause automatically when audio is rerouted from a headset to
device speakers.
|
SimpleExoPlayer.Builder |
setLivePlaybackSpeedControl(LivePlaybackSpeedControl livePlaybackSpeedControl) |
Sets the
LivePlaybackSpeedControl that will control the playback speed when playing
live streams, in order to maintain a steady target offset from the live stream edge. |
SimpleExoPlayer.Builder |
setLoadControl(LoadControl loadControl) |
Sets the
LoadControl that will be used by the player. |
SimpleExoPlayer.Builder |
setLooper(Looper looper) |
Sets the
Looper that must be used for all calls to the player and that is used to
call listeners on. |
SimpleExoPlayer.Builder |
setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) |
Sets the
MediaSourceFactory that will be used by the player. |
SimpleExoPlayer.Builder |
setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems) |
Sets whether to pause playback at the end of each media item.
|
SimpleExoPlayer.Builder |
setPriorityTaskManager(PriorityTaskManager priorityTaskManager) |
Sets an
PriorityTaskManager that will be used by the player. |
SimpleExoPlayer.Builder |
setReleaseTimeoutMs(long releaseTimeoutMs) |
Sets a timeout for calls to
SimpleExoPlayer.release() and SimpleExoPlayer.setForegroundMode(boolean) . |
SimpleExoPlayer.Builder |
setSeekParameters(SeekParameters seekParameters) |
Sets the parameters that control how seek operations are performed.
|
SimpleExoPlayer.Builder |
setSkipSilenceEnabled(boolean skipSilenceEnabled) |
Sets whether silences silences in the audio stream is enabled.
|
SimpleExoPlayer.Builder |
setTrackSelector(TrackSelector trackSelector) |
Sets the
TrackSelector that will be used by the player. |
SimpleExoPlayer.Builder |
setUseLazyPreparation(boolean useLazyPreparation) |
Sets whether media sources should be initialized lazily.
|
SimpleExoPlayer.Builder |
setVideoScalingMode(int videoScalingMode) |
Sets the
C.VideoScalingMode that will be used by the player. |
SimpleExoPlayer.Builder |
setWakeMode(int wakeMode) |
Sets the
C.WakeMode that will be used by the player. |
public Builder(Context context)
Use Builder(Context, RenderersFactory)
, Builder(Context,
RenderersFactory)
or Builder(Context, RenderersFactory, ExtractorsFactory)
instead,
if you intend to provide a custom RenderersFactory
or a custom ExtractorsFactory
. This is to ensure that ProGuard or R8 can remove ExoPlayer's DefaultRenderersFactory
and DefaultExtractorsFactory
from the APK.
The builder uses the following default values:
RenderersFactory
: DefaultRenderersFactory
TrackSelector
: DefaultTrackSelector
MediaSourceFactory
: DefaultMediaSourceFactory
LoadControl
: DefaultLoadControl
BandwidthMeter
: DefaultBandwidthMeter.getSingletonInstance(Context)
LivePlaybackSpeedControl
: DefaultLivePlaybackSpeedControl
Looper
: The Looper
associated with the current thread, or the Looper
of the application's main thread if the current thread doesn't have a Looper
AnalyticsCollector
: AnalyticsCollector
with Clock.DEFAULT
PriorityTaskManager
: null
(not used)
AudioAttributes
: AudioAttributes.DEFAULT
, not handling audio focus
C.WakeMode
: C.WAKE_MODE_NONE
handleAudioBecomingNoisy
: false
skipSilenceEnabled
: false
C.VideoScalingMode
: C.VIDEO_SCALING_MODE_DEFAULT
useLazyPreparation
: true
SeekParameters
: SeekParameters.DEFAULT
releaseTimeoutMs
: ExoPlayer.DEFAULT_RELEASE_TIMEOUT_MS
detachSurfaceTimeoutMs
: SimpleExoPlayer.DEFAULT_DETACH_SURFACE_TIMEOUT_MS
pauseAtEndOfMediaItems
: false
Clock
: Clock.DEFAULT
context
- A Context
.public Builder(Context context, RenderersFactory renderersFactory)
RenderersFactory
.
See Builder(Context)
for a list of default values.
public Builder(Context context, ExtractorsFactory extractorsFactory)
ExtractorsFactory
.
See Builder(Context)
for a list of default values.
context
- A Context
.extractorsFactory
- An ExtractorsFactory
used to extract progressive media from
its container.public Builder(Context context, RenderersFactory renderersFactory, ExtractorsFactory extractorsFactory)
RenderersFactory
and ExtractorsFactory
.
See Builder(Context)
for a list of default values.
context
- A Context
.renderersFactory
- A factory for creating Renderers
to be used by the
player.extractorsFactory
- An ExtractorsFactory
used to extract progressive media from
its container.public Builder(Context context, RenderersFactory renderersFactory, TrackSelector trackSelector, MediaSourceFactory mediaSourceFactory, LoadControl loadControl, BandwidthMeter bandwidthMeter, AnalyticsCollector analyticsCollector)
Note that this constructor is only useful to try and ensure that ExoPlayer's default components can be removed by ProGuard or R8.
context
- A Context
.renderersFactory
- A factory for creating Renderers
to be used by the
player.trackSelector
- A TrackSelector
.mediaSourceFactory
- A MediaSourceFactory
.loadControl
- A LoadControl
.bandwidthMeter
- A BandwidthMeter
.analyticsCollector
- An AnalyticsCollector
.public SimpleExoPlayer.Builder setTrackSelector(TrackSelector trackSelector)
TrackSelector
that will be used by the player.trackSelector
- A TrackSelector
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory)
MediaSourceFactory
that will be used by the player.mediaSourceFactory
- A MediaSourceFactory
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setLoadControl(LoadControl loadControl)
LoadControl
that will be used by the player.loadControl
- A LoadControl
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setBandwidthMeter(BandwidthMeter bandwidthMeter)
BandwidthMeter
that will be used by the player.bandwidthMeter
- A BandwidthMeter
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setLooper(Looper looper)
Looper
that must be used for all calls to the player and that is used to
call listeners on.looper
- A Looper
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector)
AnalyticsCollector
that will collect and forward all player events.analyticsCollector
- An AnalyticsCollector
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager)
PriorityTaskManager
that will be used by the player.
The priority C.PRIORITY_PLAYBACK
will be set while the player is loading.
priorityTaskManager
- A PriorityTaskManager
, or null to not use one.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus)
AudioAttributes
that will be used by the player and whether to handle audio
focus.
If audio focus should be handled, the AudioAttributes.usage
must be C.USAGE_MEDIA
or C.USAGE_GAME
. Other usages will throw an IllegalArgumentException
.
audioAttributes
- AudioAttributes
.handleAudioFocus
- Whether the player should handle audio focus.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setWakeMode(@WakeMode int wakeMode)
C.WakeMode
that will be used by the player.
Enabling this feature requires the Manifest.permission.WAKE_LOCK
permission. It should be used together with a foreground Service
for use
cases where playback occurs and the screen is off (e.g. background audio playback). It is not
useful when the screen will be kept on during playback (e.g. foreground video playback).
When enabled, the locks (PowerManager.WakeLock
/ WifiManager.WifiLock
) will be held whenever the player is in the Player.STATE_READY
or Player.STATE_BUFFERING
states with playWhenReady = true
. The locks
held depend on the specified C.WakeMode
.
wakeMode
- A C.WakeMode
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy)
handleAudioBecomingNoisy
- Whether the player should pause automatically when audio is
rerouted from a headset to device speakers.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setSkipSilenceEnabled(boolean skipSilenceEnabled)
skipSilenceEnabled
- Whether skipping silences is enabled.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setVideoScalingMode(@VideoScalingMode int videoScalingMode)
C.VideoScalingMode
that will be used by the player.
Note that the scaling mode only applies if a MediaCodec
-based video Renderer
is enabled and if the output surface is owned by a SurfaceView
.
videoScalingMode
- A C.VideoScalingMode
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setUseLazyPreparation(boolean useLazyPreparation)
If false, all initial preparation steps (e.g., manifest loads) happen immediately. If true, these initial preparations are triggered only when the player starts buffering the media.
useLazyPreparation
- Whether to use lazy preparation.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setSeekParameters(SeekParameters seekParameters)
seekParameters
- The SeekParameters
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setReleaseTimeoutMs(long releaseTimeoutMs)
SimpleExoPlayer.release()
and SimpleExoPlayer.setForegroundMode(boolean)
.
If a call to SimpleExoPlayer.release()
or SimpleExoPlayer.setForegroundMode(boolean)
takes more than
timeoutMs
to complete, the player will report an error via Player.EventListener.onPlayerError(com.google.android.exoplayer2.ExoPlaybackException)
.
releaseTimeoutMs
- The release timeout, in milliseconds.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setDetachSurfaceTimeoutMs(long detachSurfaceTimeoutMs)
If detaching a surface or replacing a surface takes more than
detachSurfaceTimeoutMs
to complete, the player will report an error via Player.EventListener.onPlayerError(com.google.android.exoplayer2.ExoPlaybackException)
.
detachSurfaceTimeoutMs
- The timeout for detaching a surface, in milliseconds.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems)
This means the player will pause at the end of each window in the current timeline
. Listeners will be informed by a call to Player.EventListener.onPlayWhenReadyChanged(boolean, int)
with the reason Player.PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM
when this happens.
pauseAtEndOfMediaItems
- Whether to pause playback at the end of each media item.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setLivePlaybackSpeedControl(LivePlaybackSpeedControl livePlaybackSpeedControl)
LivePlaybackSpeedControl
that will control the playback speed when playing
live streams, in order to maintain a steady target offset from the live stream edge.livePlaybackSpeedControl
- The LivePlaybackSpeedControl
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer.Builder setClock(Clock clock)
Clock
that will be used by the player. Should only be set for testing
purposes.clock
- A Clock
.IllegalStateException
- If build()
has already been called.public SimpleExoPlayer build()
SimpleExoPlayer
instance.IllegalStateException
- If this method has already been called.