Move SimpleExoPlayer.Builder logic to ExoPlayer.Builder.

SimpleExoPlayer Builder now wraps an ExoPlayer.Builder, rather than the
other way round.

PiperOrigin-RevId: 404509106
This commit is contained in:
samrobinson 2021-10-20 14:19:38 +01:00 committed by Oliver Woodman
parent 2ebbdbef8c
commit 140ef753f7
2 changed files with 164 additions and 157 deletions

View File

@ -15,6 +15,9 @@
*/ */
package com.google.android.exoplayer2; package com.google.android.exoplayer2;
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkState;
import android.content.Context; import android.content.Context;
import android.media.AudioTrack; import android.media.AudioTrack;
import android.media.MediaCodec; import android.media.MediaCodec;
@ -359,7 +362,34 @@ public interface ExoPlayer extends Player {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
final class Builder { final class Builder {
private final SimpleExoPlayer.Builder wrappedBuilder; /* package */ final Context context;
/* package */ final RenderersFactory renderersFactory;
/* package */ Clock clock;
/* package */ long foregroundModeTimeoutMs;
/* package */ TrackSelector trackSelector;
/* package */ MediaSourceFactory mediaSourceFactory;
/* package */ LoadControl loadControl;
/* package */ BandwidthMeter bandwidthMeter;
/* package */ AnalyticsCollector analyticsCollector;
/* package */ Looper looper;
@Nullable /* package */ PriorityTaskManager priorityTaskManager;
/* package */ AudioAttributes audioAttributes;
/* package */ boolean handleAudioFocus;
@C.WakeMode /* package */ int wakeMode;
/* package */ boolean handleAudioBecomingNoisy;
/* package */ boolean skipSilenceEnabled;
@C.VideoScalingMode /* package */ int videoScalingMode;
@C.VideoChangeFrameRateStrategy /* package */ int videoChangeFrameRateStrategy;
/* package */ boolean useLazyPreparation;
/* package */ SeekParameters seekParameters;
/* package */ long seekBackIncrementMs;
/* package */ long seekForwardIncrementMs;
/* package */ LivePlaybackSpeedControl livePlaybackSpeedControl;
/* package */ long releaseTimeoutMs;
/* package */ long detachSurfaceTimeoutMs;
/* package */ boolean pauseAtEndOfMediaItems;
/* package */ boolean buildCalled;
/** /**
* Creates a builder. * Creates a builder.
@ -404,7 +434,7 @@ public interface ExoPlayer extends Player {
* @param context A {@link Context}. * @param context A {@link Context}.
*/ */
public Builder(Context context) { public Builder(Context context) {
wrappedBuilder = new SimpleExoPlayer.Builder(context); this(context, new DefaultRenderersFactory(context), new DefaultExtractorsFactory());
} }
/** /**
@ -417,7 +447,7 @@ public interface ExoPlayer extends Player {
* player. * player.
*/ */
public Builder(Context context, RenderersFactory renderersFactory) { public Builder(Context context, RenderersFactory renderersFactory) {
wrappedBuilder = new SimpleExoPlayer.Builder(context, renderersFactory); this(context, renderersFactory, new DefaultExtractorsFactory());
} }
/** /**
@ -430,7 +460,7 @@ public interface ExoPlayer extends Player {
* its container. * its container.
*/ */
public Builder(Context context, ExtractorsFactory extractorsFactory) { public Builder(Context context, ExtractorsFactory extractorsFactory) {
wrappedBuilder = new SimpleExoPlayer.Builder(context, extractorsFactory); this(context, new DefaultRenderersFactory(context), extractorsFactory);
} }
/** /**
@ -446,7 +476,14 @@ public interface ExoPlayer extends Player {
*/ */
public Builder( public Builder(
Context context, RenderersFactory renderersFactory, ExtractorsFactory extractorsFactory) { Context context, RenderersFactory renderersFactory, ExtractorsFactory extractorsFactory) {
wrappedBuilder = new SimpleExoPlayer.Builder(context, renderersFactory, extractorsFactory); this(
context,
renderersFactory,
new DefaultTrackSelector(context),
new DefaultMediaSourceFactory(context, extractorsFactory),
new DefaultLoadControl(),
DefaultBandwidthMeter.getSingletonInstance(context),
new AnalyticsCollector(Clock.DEFAULT));
} }
/** /**
@ -472,15 +509,26 @@ public interface ExoPlayer extends Player {
LoadControl loadControl, LoadControl loadControl,
BandwidthMeter bandwidthMeter, BandwidthMeter bandwidthMeter,
AnalyticsCollector analyticsCollector) { AnalyticsCollector analyticsCollector) {
wrappedBuilder = this.context = context;
new SimpleExoPlayer.Builder( this.renderersFactory = renderersFactory;
context, this.trackSelector = trackSelector;
renderersFactory, this.mediaSourceFactory = mediaSourceFactory;
trackSelector, this.loadControl = loadControl;
mediaSourceFactory, this.bandwidthMeter = bandwidthMeter;
loadControl, this.analyticsCollector = analyticsCollector;
bandwidthMeter, looper = Util.getCurrentOrMainLooper();
analyticsCollector); audioAttributes = AudioAttributes.DEFAULT;
wakeMode = C.WAKE_MODE_NONE;
videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
videoChangeFrameRateStrategy = C.VIDEO_CHANGE_FRAME_RATE_STRATEGY_ONLY_IF_SEAMLESS;
useLazyPreparation = true;
seekParameters = SeekParameters.DEFAULT;
seekBackIncrementMs = C.DEFAULT_SEEK_BACK_INCREMENT_MS;
seekForwardIncrementMs = C.DEFAULT_SEEK_FORWARD_INCREMENT_MS;
livePlaybackSpeedControl = new DefaultLivePlaybackSpeedControl.Builder().build();
clock = Clock.DEFAULT;
releaseTimeoutMs = DEFAULT_RELEASE_TIMEOUT_MS;
detachSurfaceTimeoutMs = DEFAULT_DETACH_SURFACE_TIMEOUT_MS;
} }
/** /**
@ -493,7 +541,8 @@ public interface ExoPlayer extends Player {
* @param timeoutMs The time limit in milliseconds. * @param timeoutMs The time limit in milliseconds.
*/ */
public Builder experimentalSetForegroundModeTimeoutMs(long timeoutMs) { public Builder experimentalSetForegroundModeTimeoutMs(long timeoutMs) {
wrappedBuilder.experimentalSetForegroundModeTimeoutMs(timeoutMs); checkState(!buildCalled);
foregroundModeTimeoutMs = timeoutMs;
return this; return this;
} }
@ -505,7 +554,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setTrackSelector(TrackSelector trackSelector) { public Builder setTrackSelector(TrackSelector trackSelector) {
wrappedBuilder.setTrackSelector(trackSelector); checkState(!buildCalled);
this.trackSelector = trackSelector;
return this; return this;
} }
@ -517,7 +567,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) { public Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) {
wrappedBuilder.setMediaSourceFactory(mediaSourceFactory); checkState(!buildCalled);
this.mediaSourceFactory = mediaSourceFactory;
return this; return this;
} }
@ -529,7 +580,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setLoadControl(LoadControl loadControl) { public Builder setLoadControl(LoadControl loadControl) {
wrappedBuilder.setLoadControl(loadControl); checkState(!buildCalled);
this.loadControl = loadControl;
return this; return this;
} }
@ -541,7 +593,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setBandwidthMeter(BandwidthMeter bandwidthMeter) { public Builder setBandwidthMeter(BandwidthMeter bandwidthMeter) {
wrappedBuilder.setBandwidthMeter(bandwidthMeter); checkState(!buildCalled);
this.bandwidthMeter = bandwidthMeter;
return this; return this;
} }
@ -554,7 +607,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setLooper(Looper looper) { public Builder setLooper(Looper looper) {
wrappedBuilder.setLooper(looper); checkState(!buildCalled);
this.looper = looper;
return this; return this;
} }
@ -566,7 +620,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector) { public Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector) {
wrappedBuilder.setAnalyticsCollector(analyticsCollector); checkState(!buildCalled);
this.analyticsCollector = analyticsCollector;
return this; return this;
} }
@ -580,7 +635,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) { public Builder setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) {
wrappedBuilder.setPriorityTaskManager(priorityTaskManager); checkState(!buildCalled);
this.priorityTaskManager = priorityTaskManager;
return this; return this;
} }
@ -598,7 +654,9 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus) { public Builder setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus) {
wrappedBuilder.setAudioAttributes(audioAttributes, handleAudioFocus); checkState(!buildCalled);
this.audioAttributes = audioAttributes;
this.handleAudioFocus = handleAudioFocus;
return this; return this;
} }
@ -620,7 +678,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setWakeMode(@C.WakeMode int wakeMode) { public Builder setWakeMode(@C.WakeMode int wakeMode) {
wrappedBuilder.setWakeMode(wakeMode); checkState(!buildCalled);
this.wakeMode = wakeMode;
return this; return this;
} }
@ -636,7 +695,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) { public Builder setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) {
wrappedBuilder.setHandleAudioBecomingNoisy(handleAudioBecomingNoisy); checkState(!buildCalled);
this.handleAudioBecomingNoisy = handleAudioBecomingNoisy;
return this; return this;
} }
@ -648,7 +708,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setSkipSilenceEnabled(boolean skipSilenceEnabled) { public Builder setSkipSilenceEnabled(boolean skipSilenceEnabled) {
wrappedBuilder.setSkipSilenceEnabled(skipSilenceEnabled); checkState(!buildCalled);
this.skipSilenceEnabled = skipSilenceEnabled;
return this; return this;
} }
@ -663,7 +724,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setVideoScalingMode(@C.VideoScalingMode int videoScalingMode) { public Builder setVideoScalingMode(@C.VideoScalingMode int videoScalingMode) {
wrappedBuilder.setVideoScalingMode(videoScalingMode); checkState(!buildCalled);
this.videoScalingMode = videoScalingMode;
return this; return this;
} }
@ -683,7 +745,8 @@ public interface ExoPlayer extends Player {
*/ */
public Builder setVideoChangeFrameRateStrategy( public Builder setVideoChangeFrameRateStrategy(
@C.VideoChangeFrameRateStrategy int videoChangeFrameRateStrategy) { @C.VideoChangeFrameRateStrategy int videoChangeFrameRateStrategy) {
wrappedBuilder.setVideoChangeFrameRateStrategy(videoChangeFrameRateStrategy); checkState(!buildCalled);
this.videoChangeFrameRateStrategy = videoChangeFrameRateStrategy;
return this; return this;
} }
@ -699,7 +762,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setUseLazyPreparation(boolean useLazyPreparation) { public Builder setUseLazyPreparation(boolean useLazyPreparation) {
wrappedBuilder.setUseLazyPreparation(useLazyPreparation); checkState(!buildCalled);
this.useLazyPreparation = useLazyPreparation;
return this; return this;
} }
@ -711,7 +775,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setSeekParameters(SeekParameters seekParameters) { public Builder setSeekParameters(SeekParameters seekParameters) {
wrappedBuilder.setSeekParameters(seekParameters); checkState(!buildCalled);
this.seekParameters = seekParameters;
return this; return this;
} }
@ -724,7 +789,9 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setSeekBackIncrementMs(@IntRange(from = 1) long seekBackIncrementMs) { public Builder setSeekBackIncrementMs(@IntRange(from = 1) long seekBackIncrementMs) {
wrappedBuilder.setSeekBackIncrementMs(seekBackIncrementMs); checkArgument(seekBackIncrementMs > 0);
checkState(!buildCalled);
this.seekBackIncrementMs = seekBackIncrementMs;
return this; return this;
} }
@ -737,7 +804,9 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setSeekForwardIncrementMs(@IntRange(from = 1) long seekForwardIncrementMs) { public Builder setSeekForwardIncrementMs(@IntRange(from = 1) long seekForwardIncrementMs) {
wrappedBuilder.setSeekForwardIncrementMs(seekForwardIncrementMs); checkArgument(seekForwardIncrementMs > 0);
checkState(!buildCalled);
this.seekForwardIncrementMs = seekForwardIncrementMs;
return this; return this;
} }
@ -753,7 +822,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setReleaseTimeoutMs(long releaseTimeoutMs) { public Builder setReleaseTimeoutMs(long releaseTimeoutMs) {
wrappedBuilder.setReleaseTimeoutMs(releaseTimeoutMs); checkState(!buildCalled);
this.releaseTimeoutMs = releaseTimeoutMs;
return this; return this;
} }
@ -769,7 +839,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setDetachSurfaceTimeoutMs(long detachSurfaceTimeoutMs) { public Builder setDetachSurfaceTimeoutMs(long detachSurfaceTimeoutMs) {
wrappedBuilder.setDetachSurfaceTimeoutMs(detachSurfaceTimeoutMs); checkState(!buildCalled);
this.detachSurfaceTimeoutMs = detachSurfaceTimeoutMs;
return this; return this;
} }
@ -786,7 +857,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems) { public Builder setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems) {
wrappedBuilder.setPauseAtEndOfMediaItems(pauseAtEndOfMediaItems); checkState(!buildCalled);
this.pauseAtEndOfMediaItems = pauseAtEndOfMediaItems;
return this; return this;
} }
@ -799,7 +871,8 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If {@link #build()} has already been called. * @throws IllegalStateException If {@link #build()} has already been called.
*/ */
public Builder setLivePlaybackSpeedControl(LivePlaybackSpeedControl livePlaybackSpeedControl) { public Builder setLivePlaybackSpeedControl(LivePlaybackSpeedControl livePlaybackSpeedControl) {
wrappedBuilder.setLivePlaybackSpeedControl(livePlaybackSpeedControl); checkState(!buildCalled);
this.livePlaybackSpeedControl = livePlaybackSpeedControl;
return this; return this;
} }
@ -813,7 +886,8 @@ public interface ExoPlayer extends Player {
*/ */
@VisibleForTesting @VisibleForTesting
public Builder setClock(Clock clock) { public Builder setClock(Clock clock) {
wrappedBuilder.setClock(clock); checkState(!buildCalled);
this.clock = clock;
return this; return this;
} }
@ -823,7 +897,13 @@ public interface ExoPlayer extends Player {
* @throws IllegalStateException If this method has already been called. * @throws IllegalStateException If this method has already been called.
*/ */
public ExoPlayer build() { public ExoPlayer build() {
return wrappedBuilder.build(); return buildSimpleExoPlayer();
}
/* package */ SimpleExoPlayer buildSimpleExoPlayer() {
checkState(!buildCalled);
buildCalled = true;
return new SimpleExoPlayer(/* builder= */ this);
} }
} }

View File

@ -28,7 +28,6 @@ import static com.google.android.exoplayer2.Renderer.MSG_SET_SKIP_SILENCE_ENABLE
import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_FRAME_METADATA_LISTENER; import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_FRAME_METADATA_LISTENER;
import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_OUTPUT; import static com.google.android.exoplayer2.Renderer.MSG_SET_VIDEO_OUTPUT;
import static com.google.android.exoplayer2.Renderer.MSG_SET_VOLUME; import static com.google.android.exoplayer2.Renderer.MSG_SET_VOLUME;
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.content.Context; import android.content.Context;
import android.graphics.Rect; import android.graphics.Rect;
@ -53,23 +52,19 @@ import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.audio.AuxEffectInfo; import com.google.android.exoplayer2.audio.AuxEffectInfo;
import com.google.android.exoplayer2.decoder.DecoderCounters; import com.google.android.exoplayer2.decoder.DecoderCounters;
import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation; import com.google.android.exoplayer2.decoder.DecoderReuseEvaluation;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ExtractorsFactory; import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataOutput; import com.google.android.exoplayer2.metadata.MetadataOutput;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceFactory; import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextOutput; import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.ConditionVariable;
@ -102,51 +97,24 @@ public class SimpleExoPlayer extends BasePlayer
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static final class Builder { public static final class Builder {
private final Context context; private final ExoPlayer.Builder wrappedBuilder;
private final RenderersFactory renderersFactory;
private Clock clock;
private long foregroundModeTimeoutMs;
private TrackSelector trackSelector;
private MediaSourceFactory mediaSourceFactory;
private LoadControl loadControl;
private BandwidthMeter bandwidthMeter;
private AnalyticsCollector analyticsCollector;
private Looper looper;
@Nullable private PriorityTaskManager priorityTaskManager;
private AudioAttributes audioAttributes;
private boolean handleAudioFocus;
@C.WakeMode private int wakeMode;
private boolean handleAudioBecomingNoisy;
private boolean skipSilenceEnabled;
@C.VideoScalingMode private int videoScalingMode;
@C.VideoChangeFrameRateStrategy private int videoChangeFrameRateStrategy;
private boolean useLazyPreparation;
private SeekParameters seekParameters;
private long seekBackIncrementMs;
private long seekForwardIncrementMs;
private LivePlaybackSpeedControl livePlaybackSpeedControl;
private long releaseTimeoutMs;
private long detachSurfaceTimeoutMs;
private boolean pauseAtEndOfMediaItems;
private boolean buildCalled;
/** @deprecated Use {@link ExoPlayer.Builder#Builder(Context)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#Builder(Context)} instead. */
@Deprecated @Deprecated
public Builder(Context context) { public Builder(Context context) {
this(context, new DefaultRenderersFactory(context), new DefaultExtractorsFactory()); wrappedBuilder = new ExoPlayer.Builder(context);
} }
/** @deprecated Use {@link ExoPlayer.Builder#Builder(Context, RenderersFactory)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#Builder(Context, RenderersFactory)} instead. */
@Deprecated @Deprecated
public Builder(Context context, RenderersFactory renderersFactory) { public Builder(Context context, RenderersFactory renderersFactory) {
this(context, renderersFactory, new DefaultExtractorsFactory()); wrappedBuilder = new ExoPlayer.Builder(context, renderersFactory);
} }
/** @deprecated Use {@link ExoPlayer.Builder#Builder(Context, ExtractorsFactory)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#Builder(Context, ExtractorsFactory)} instead. */
@Deprecated @Deprecated
public Builder(Context context, ExtractorsFactory extractorsFactory) { public Builder(Context context, ExtractorsFactory extractorsFactory) {
this(context, new DefaultRenderersFactory(context), extractorsFactory); wrappedBuilder = new ExoPlayer.Builder(context, extractorsFactory);
} }
/** /**
@ -156,14 +124,7 @@ public class SimpleExoPlayer extends BasePlayer
@Deprecated @Deprecated
public Builder( public Builder(
Context context, RenderersFactory renderersFactory, ExtractorsFactory extractorsFactory) { Context context, RenderersFactory renderersFactory, ExtractorsFactory extractorsFactory) {
this( wrappedBuilder = new ExoPlayer.Builder(context, renderersFactory, extractorsFactory);
context,
renderersFactory,
new DefaultTrackSelector(context),
new DefaultMediaSourceFactory(context, extractorsFactory),
new DefaultLoadControl(),
DefaultBandwidthMeter.getSingletonInstance(context),
new AnalyticsCollector(Clock.DEFAULT));
} }
/** /**
@ -179,26 +140,15 @@ public class SimpleExoPlayer extends BasePlayer
LoadControl loadControl, LoadControl loadControl,
BandwidthMeter bandwidthMeter, BandwidthMeter bandwidthMeter,
AnalyticsCollector analyticsCollector) { AnalyticsCollector analyticsCollector) {
this.context = context; wrappedBuilder =
this.renderersFactory = renderersFactory; new ExoPlayer.Builder(
this.trackSelector = trackSelector; context,
this.mediaSourceFactory = mediaSourceFactory; renderersFactory,
this.loadControl = loadControl; trackSelector,
this.bandwidthMeter = bandwidthMeter; mediaSourceFactory,
this.analyticsCollector = analyticsCollector; loadControl,
looper = Util.getCurrentOrMainLooper(); bandwidthMeter,
audioAttributes = AudioAttributes.DEFAULT; analyticsCollector);
wakeMode = C.WAKE_MODE_NONE;
videoScalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
videoChangeFrameRateStrategy = C.VIDEO_CHANGE_FRAME_RATE_STRATEGY_ONLY_IF_SEAMLESS;
useLazyPreparation = true;
seekParameters = SeekParameters.DEFAULT;
seekBackIncrementMs = C.DEFAULT_SEEK_BACK_INCREMENT_MS;
seekForwardIncrementMs = C.DEFAULT_SEEK_FORWARD_INCREMENT_MS;
livePlaybackSpeedControl = new DefaultLivePlaybackSpeedControl.Builder().build();
clock = Clock.DEFAULT;
releaseTimeoutMs = DEFAULT_RELEASE_TIMEOUT_MS;
detachSurfaceTimeoutMs = DEFAULT_DETACH_SURFACE_TIMEOUT_MS;
} }
/** /**
@ -207,16 +157,14 @@ public class SimpleExoPlayer extends BasePlayer
*/ */
@Deprecated @Deprecated
public Builder experimentalSetForegroundModeTimeoutMs(long timeoutMs) { public Builder experimentalSetForegroundModeTimeoutMs(long timeoutMs) {
Assertions.checkState(!buildCalled); wrappedBuilder.experimentalSetForegroundModeTimeoutMs(timeoutMs);
foregroundModeTimeoutMs = timeoutMs;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setTrackSelector(TrackSelector)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setTrackSelector(TrackSelector)} instead. */
@Deprecated @Deprecated
public Builder setTrackSelector(TrackSelector trackSelector) { public Builder setTrackSelector(TrackSelector trackSelector) {
Assertions.checkState(!buildCalled); wrappedBuilder.setTrackSelector(trackSelector);
this.trackSelector = trackSelector;
return this; return this;
} }
@ -225,32 +173,28 @@ public class SimpleExoPlayer extends BasePlayer
*/ */
@Deprecated @Deprecated
public Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) { public Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) {
Assertions.checkState(!buildCalled); wrappedBuilder.setMediaSourceFactory(mediaSourceFactory);
this.mediaSourceFactory = mediaSourceFactory;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setLoadControl(LoadControl)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setLoadControl(LoadControl)} instead. */
@Deprecated @Deprecated
public Builder setLoadControl(LoadControl loadControl) { public Builder setLoadControl(LoadControl loadControl) {
Assertions.checkState(!buildCalled); wrappedBuilder.setLoadControl(loadControl);
this.loadControl = loadControl;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setBandwidthMeter(BandwidthMeter)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setBandwidthMeter(BandwidthMeter)} instead. */
@Deprecated @Deprecated
public Builder setBandwidthMeter(BandwidthMeter bandwidthMeter) { public Builder setBandwidthMeter(BandwidthMeter bandwidthMeter) {
Assertions.checkState(!buildCalled); wrappedBuilder.setBandwidthMeter(bandwidthMeter);
this.bandwidthMeter = bandwidthMeter;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setLooper(Looper)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setLooper(Looper)} instead. */
@Deprecated @Deprecated
public Builder setLooper(Looper looper) { public Builder setLooper(Looper looper) {
Assertions.checkState(!buildCalled); wrappedBuilder.setLooper(looper);
this.looper = looper;
return this; return this;
} }
@ -259,8 +203,7 @@ public class SimpleExoPlayer extends BasePlayer
*/ */
@Deprecated @Deprecated
public Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector) { public Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector) {
Assertions.checkState(!buildCalled); wrappedBuilder.setAnalyticsCollector(analyticsCollector);
this.analyticsCollector = analyticsCollector;
return this; return this;
} }
@ -270,8 +213,7 @@ public class SimpleExoPlayer extends BasePlayer
*/ */
@Deprecated @Deprecated
public Builder setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) { public Builder setPriorityTaskManager(@Nullable PriorityTaskManager priorityTaskManager) {
Assertions.checkState(!buildCalled); wrappedBuilder.setPriorityTaskManager(priorityTaskManager);
this.priorityTaskManager = priorityTaskManager;
return this; return this;
} }
@ -281,41 +223,35 @@ public class SimpleExoPlayer extends BasePlayer
*/ */
@Deprecated @Deprecated
public Builder setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus) { public Builder setAudioAttributes(AudioAttributes audioAttributes, boolean handleAudioFocus) {
Assertions.checkState(!buildCalled); wrappedBuilder.setAudioAttributes(audioAttributes, handleAudioFocus);
this.audioAttributes = audioAttributes;
this.handleAudioFocus = handleAudioFocus;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setWakeMode(int)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setWakeMode(int)} instead. */
@Deprecated @Deprecated
public Builder setWakeMode(@C.WakeMode int wakeMode) { public Builder setWakeMode(@C.WakeMode int wakeMode) {
Assertions.checkState(!buildCalled); wrappedBuilder.setWakeMode(wakeMode);
this.wakeMode = wakeMode;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setHandleAudioBecomingNoisy(boolean)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setHandleAudioBecomingNoisy(boolean)} instead. */
@Deprecated @Deprecated
public Builder setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) { public Builder setHandleAudioBecomingNoisy(boolean handleAudioBecomingNoisy) {
Assertions.checkState(!buildCalled); wrappedBuilder.setHandleAudioBecomingNoisy(handleAudioBecomingNoisy);
this.handleAudioBecomingNoisy = handleAudioBecomingNoisy;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setSkipSilenceEnabled(boolean)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setSkipSilenceEnabled(boolean)} instead. */
@Deprecated @Deprecated
public Builder setSkipSilenceEnabled(boolean skipSilenceEnabled) { public Builder setSkipSilenceEnabled(boolean skipSilenceEnabled) {
Assertions.checkState(!buildCalled); wrappedBuilder.setSkipSilenceEnabled(skipSilenceEnabled);
this.skipSilenceEnabled = skipSilenceEnabled;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setVideoScalingMode(int)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setVideoScalingMode(int)} instead. */
@Deprecated @Deprecated
public Builder setVideoScalingMode(@C.VideoScalingMode int videoScalingMode) { public Builder setVideoScalingMode(@C.VideoScalingMode int videoScalingMode) {
Assertions.checkState(!buildCalled); wrappedBuilder.setVideoScalingMode(videoScalingMode);
this.videoScalingMode = videoScalingMode;
return this; return this;
} }
@ -323,66 +259,56 @@ public class SimpleExoPlayer extends BasePlayer
@Deprecated @Deprecated
public Builder setVideoChangeFrameRateStrategy( public Builder setVideoChangeFrameRateStrategy(
@C.VideoChangeFrameRateStrategy int videoChangeFrameRateStrategy) { @C.VideoChangeFrameRateStrategy int videoChangeFrameRateStrategy) {
Assertions.checkState(!buildCalled); wrappedBuilder.setVideoChangeFrameRateStrategy(videoChangeFrameRateStrategy);
this.videoChangeFrameRateStrategy = videoChangeFrameRateStrategy;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setUseLazyPreparation(boolean)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setUseLazyPreparation(boolean)} instead. */
@Deprecated @Deprecated
public Builder setUseLazyPreparation(boolean useLazyPreparation) { public Builder setUseLazyPreparation(boolean useLazyPreparation) {
Assertions.checkState(!buildCalled); wrappedBuilder.setUseLazyPreparation(useLazyPreparation);
this.useLazyPreparation = useLazyPreparation;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setSeekParameters(SeekParameters)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setSeekParameters(SeekParameters)} instead. */
@Deprecated @Deprecated
public Builder setSeekParameters(SeekParameters seekParameters) { public Builder setSeekParameters(SeekParameters seekParameters) {
Assertions.checkState(!buildCalled); wrappedBuilder.setSeekParameters(seekParameters);
this.seekParameters = seekParameters;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setSeekBackIncrementMs(long)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setSeekBackIncrementMs(long)} instead. */
@Deprecated @Deprecated
public Builder setSeekBackIncrementMs(@IntRange(from = 1) long seekBackIncrementMs) { public Builder setSeekBackIncrementMs(@IntRange(from = 1) long seekBackIncrementMs) {
checkArgument(seekBackIncrementMs > 0); wrappedBuilder.setSeekBackIncrementMs(seekBackIncrementMs);
Assertions.checkState(!buildCalled);
this.seekBackIncrementMs = seekBackIncrementMs;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setSeekForwardIncrementMs(long)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setSeekForwardIncrementMs(long)} instead. */
@Deprecated @Deprecated
public Builder setSeekForwardIncrementMs(@IntRange(from = 1) long seekForwardIncrementMs) { public Builder setSeekForwardIncrementMs(@IntRange(from = 1) long seekForwardIncrementMs) {
checkArgument(seekForwardIncrementMs > 0); wrappedBuilder.setSeekForwardIncrementMs(seekForwardIncrementMs);
Assertions.checkState(!buildCalled);
this.seekForwardIncrementMs = seekForwardIncrementMs;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setReleaseTimeoutMs(long)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setReleaseTimeoutMs(long)} instead. */
@Deprecated @Deprecated
public Builder setReleaseTimeoutMs(long releaseTimeoutMs) { public Builder setReleaseTimeoutMs(long releaseTimeoutMs) {
Assertions.checkState(!buildCalled); wrappedBuilder.setReleaseTimeoutMs(releaseTimeoutMs);
this.releaseTimeoutMs = releaseTimeoutMs;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setDetachSurfaceTimeoutMs(long)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setDetachSurfaceTimeoutMs(long)} instead. */
@Deprecated @Deprecated
public Builder setDetachSurfaceTimeoutMs(long detachSurfaceTimeoutMs) { public Builder setDetachSurfaceTimeoutMs(long detachSurfaceTimeoutMs) {
Assertions.checkState(!buildCalled); wrappedBuilder.setDetachSurfaceTimeoutMs(detachSurfaceTimeoutMs);
this.detachSurfaceTimeoutMs = detachSurfaceTimeoutMs;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#setPauseAtEndOfMediaItems(boolean)} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#setPauseAtEndOfMediaItems(boolean)} instead. */
@Deprecated @Deprecated
public Builder setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems) { public Builder setPauseAtEndOfMediaItems(boolean pauseAtEndOfMediaItems) {
Assertions.checkState(!buildCalled); wrappedBuilder.setPauseAtEndOfMediaItems(pauseAtEndOfMediaItems);
this.pauseAtEndOfMediaItems = pauseAtEndOfMediaItems;
return this; return this;
} }
@ -392,8 +318,7 @@ public class SimpleExoPlayer extends BasePlayer
*/ */
@Deprecated @Deprecated
public Builder setLivePlaybackSpeedControl(LivePlaybackSpeedControl livePlaybackSpeedControl) { public Builder setLivePlaybackSpeedControl(LivePlaybackSpeedControl livePlaybackSpeedControl) {
Assertions.checkState(!buildCalled); wrappedBuilder.setLivePlaybackSpeedControl(livePlaybackSpeedControl);
this.livePlaybackSpeedControl = livePlaybackSpeedControl;
return this; return this;
} }
@ -401,17 +326,14 @@ public class SimpleExoPlayer extends BasePlayer
@Deprecated @Deprecated
@VisibleForTesting @VisibleForTesting
public Builder setClock(Clock clock) { public Builder setClock(Clock clock) {
Assertions.checkState(!buildCalled); wrappedBuilder.setClock(clock);
this.clock = clock;
return this; return this;
} }
/** @deprecated Use {@link ExoPlayer.Builder#build()} instead. */ /** @deprecated Use {@link ExoPlayer.Builder#build()} instead. */
@Deprecated @Deprecated
public SimpleExoPlayer build() { public SimpleExoPlayer build() {
Assertions.checkState(!buildCalled); return wrappedBuilder.buildSimpleExoPlayer();
buildCalled = true;
return new SimpleExoPlayer(/* builder= */ this);
} }
} }
@ -463,7 +385,7 @@ public class SimpleExoPlayer extends BasePlayer
private DeviceInfo deviceInfo; private DeviceInfo deviceInfo;
private VideoSize videoSize; private VideoSize videoSize;
/** @deprecated Use the {@link Builder} and pass it to {@link #SimpleExoPlayer(Builder)}. */ /** @deprecated Use the {@link ExoPlayer.Builder}. */
@Deprecated @Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected SimpleExoPlayer( protected SimpleExoPlayer(
@ -478,7 +400,7 @@ public class SimpleExoPlayer extends BasePlayer
Clock clock, Clock clock,
Looper applicationLooper) { Looper applicationLooper) {
this( this(
new Builder(context, renderersFactory) new ExoPlayer.Builder(context, renderersFactory)
.setTrackSelector(trackSelector) .setTrackSelector(trackSelector)
.setMediaSourceFactory(mediaSourceFactory) .setMediaSourceFactory(mediaSourceFactory)
.setLoadControl(loadControl) .setLoadControl(loadControl)
@ -490,8 +412,13 @@ public class SimpleExoPlayer extends BasePlayer
} }
/** @param builder The {@link Builder} to obtain all construction parameters. */ /** @param builder The {@link Builder} to obtain all construction parameters. */
@SuppressWarnings("deprecation")
protected SimpleExoPlayer(Builder builder) { protected SimpleExoPlayer(Builder builder) {
this(builder.wrappedBuilder);
}
/** @param builder The {@link ExoPlayer.Builder} to obtain all construction parameters. */
@SuppressWarnings("deprecation")
/* package */ SimpleExoPlayer(ExoPlayer.Builder builder) {
constructorFinished = new ConditionVariable(); constructorFinished = new ConditionVariable();
try { try {
applicationContext = builder.context.getApplicationContext(); applicationContext = builder.context.getApplicationContext();