public static final class ExoPlayer.Builder extends Object
ExoPlayer
instances.
See Builder(Context, Renderer...)
for the list of default values.
Constructor | Description |
---|---|
Builder(Context context,
Renderer... renderers) |
Creates a builder with a list of
Renderers . |
Builder(Renderer[] renderers,
TrackSelector trackSelector,
MediaSourceFactory mediaSourceFactory,
LoadControl loadControl,
BandwidthMeter bandwidthMeter) |
Creates a builder with the specified custom components.
|
Modifier and Type | Method | Description |
---|---|---|
ExoPlayer |
build() |
Builds an
ExoPlayer instance. |
ExoPlayer.Builder |
experimentalSetForegroundModeTimeoutMs(long timeoutMs) |
Set a limit on the time a call to
ExoPlayer.setForegroundMode(boolean) can spend. |
ExoPlayer.Builder |
setAnalyticsCollector(AnalyticsCollector analyticsCollector) |
Sets the
AnalyticsCollector that will collect and forward all player events. |
ExoPlayer.Builder |
setBandwidthMeter(BandwidthMeter bandwidthMeter) |
Sets the
BandwidthMeter that will be used by the player. |
ExoPlayer.Builder |
setClock(Clock clock) |
Sets the
Clock that will be used by the player. |
ExoPlayer.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. |
ExoPlayer.Builder |
setLoadControl(LoadControl loadControl) |
Sets the
LoadControl that will be used by the player. |
ExoPlayer.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. |
ExoPlayer.Builder |
setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) |
Sets the
MediaSourceFactory that will be used by the player. |
ExoPlayer.Builder |
setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems) |
Sets whether to pause playback at the end of each media item.
|
ExoPlayer.Builder |
setReleaseTimeoutMs(long releaseTimeoutMs) |
Sets a timeout for calls to
Player.release() and ExoPlayer.setForegroundMode(boolean) . |
ExoPlayer.Builder |
setSeekParameters(SeekParameters seekParameters) |
Sets the parameters that control how seek operations are performed.
|
ExoPlayer.Builder |
setTrackSelector(TrackSelector trackSelector) |
Sets the
TrackSelector that will be used by the player. |
ExoPlayer.Builder |
setUseLazyPreparation(boolean useLazyPreparation) |
Sets whether media sources should be initialized lazily.
|
public Builder(Context context, Renderer... renderers)
Renderers
.
The builder uses the following default values:
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
useLazyPreparation
: true
SeekParameters
: SeekParameters.DEFAULT
releaseTimeoutMs
: ExoPlayer.DEFAULT_RELEASE_TIMEOUT_MS
pauseAtEndOfMediaItems
: false
Clock
: Clock.DEFAULT
public Builder(Renderer[] renderers, TrackSelector trackSelector, MediaSourceFactory mediaSourceFactory, LoadControl loadControl, BandwidthMeter bandwidthMeter)
Note that this constructor is only useful to try and ensure that ExoPlayer's default components can be removed by ProGuard or R8.
renderers
- The Renderers
to be used by the player.trackSelector
- A TrackSelector
.mediaSourceFactory
- A MediaSourceFactory
.loadControl
- A LoadControl
.bandwidthMeter
- A BandwidthMeter
.public ExoPlayer.Builder experimentalSetForegroundModeTimeoutMs(long timeoutMs)
ExoPlayer.setForegroundMode(boolean)
can spend. If a call to
ExoPlayer.setForegroundMode(boolean)
takes more than timeoutMs
milliseconds to
complete, the player will raise an error via Player.EventListener.onPlayerError(com.google.android.exoplayer2.ExoPlaybackException)
.
This method is experimental, and will be renamed or removed in a future release.
timeoutMs
- The time limit in milliseconds.public ExoPlayer.Builder setTrackSelector(TrackSelector trackSelector)
TrackSelector
that will be used by the player.trackSelector
- A TrackSelector
.IllegalStateException
- If build()
has already been called.public ExoPlayer.Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory)
MediaSourceFactory
that will be used by the player.mediaSourceFactory
- A MediaSourceFactory
.IllegalStateException
- If build()
has already been called.public ExoPlayer.Builder setLoadControl(LoadControl loadControl)
LoadControl
that will be used by the player.loadControl
- A LoadControl
.IllegalStateException
- If build()
has already been called.public ExoPlayer.Builder setBandwidthMeter(BandwidthMeter bandwidthMeter)
BandwidthMeter
that will be used by the player.bandwidthMeter
- A BandwidthMeter
.IllegalStateException
- If build()
has already been called.public ExoPlayer.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 ExoPlayer.Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector)
AnalyticsCollector
that will collect and forward all player events.analyticsCollector
- An AnalyticsCollector
.IllegalStateException
- If build()
has already been called.public ExoPlayer.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 ExoPlayer.Builder setSeekParameters(SeekParameters seekParameters)
seekParameters
- The SeekParameters
.IllegalStateException
- If build()
has already been called.public ExoPlayer.Builder setReleaseTimeoutMs(long releaseTimeoutMs)
Player.release()
and ExoPlayer.setForegroundMode(boolean)
.
If a call to Player.release()
or ExoPlayer.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 ExoPlayer.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 ExoPlayer.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 ExoPlayer.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 ExoPlayer build()
ExoPlayer
instance.IllegalStateException
- If build
has already been called.