diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java
index 991be9b08b..2bed5d6f8b 100644
--- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java
+++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java
@@ -19,6 +19,7 @@ import android.content.Context;
import android.os.Looper;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
+import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer;
import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.source.ClippingMediaSource;
@@ -138,6 +139,8 @@ public interface ExoPlayer extends Player {
private LoadControl loadControl;
private BandwidthMeter bandwidthMeter;
private Looper looper;
+ private AnalyticsCollector analyticsCollector;
+ private boolean useLazyPreparation;
private boolean buildCalled;
/**
@@ -152,6 +155,8 @@ public interface ExoPlayer extends Player {
*
{@link Looper}: The {@link Looper} associated with the current thread, or the {@link
* Looper} of the application's main thread if the current thread doesn't have a {@link
* Looper}
+ * {@link AnalyticsCollector}: {@link AnalyticsCollector} with {@link Clock#DEFAULT}
+ * {@code useLazyPreparation}: {@code true}
* {@link Clock}: {@link Clock#DEFAULT}
*
*
@@ -165,6 +170,8 @@ public interface ExoPlayer extends Player {
new DefaultLoadControl(),
DefaultBandwidthMeter.getSingletonInstance(context),
Util.getLooper(),
+ new AnalyticsCollector(Clock.DEFAULT),
+ /* useLazyPreparation= */ true,
Clock.DEFAULT);
}
@@ -180,6 +187,8 @@ public interface ExoPlayer extends Player {
* @param loadControl A {@link LoadControl}.
* @param bandwidthMeter A {@link BandwidthMeter}.
* @param looper A {@link Looper} that must be used for all calls to the player.
+ * @param analyticsCollector An {@link AnalyticsCollector}.
+ * @param useLazyPreparation Whether media sources should be initialized lazily.
* @param clock A {@link Clock}. Should always be {@link Clock#DEFAULT}.
*/
public Builder(
@@ -188,6 +197,8 @@ public interface ExoPlayer extends Player {
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
Looper looper,
+ AnalyticsCollector analyticsCollector,
+ boolean useLazyPreparation,
Clock clock) {
Assertions.checkArgument(renderers.length > 0);
this.renderers = renderers;
@@ -195,6 +206,8 @@ public interface ExoPlayer extends Player {
this.loadControl = loadControl;
this.bandwidthMeter = bandwidthMeter;
this.looper = looper;
+ this.analyticsCollector = analyticsCollector;
+ this.useLazyPreparation = useLazyPreparation;
this.clock = clock;
}
@@ -251,6 +264,36 @@ public interface ExoPlayer extends Player {
return this;
}
+ /**
+ * Sets the {@link AnalyticsCollector} that will collect and forward all player events.
+ *
+ * @param analyticsCollector An {@link AnalyticsCollector}.
+ * @return This builder.
+ * @throws IllegalStateException If {@link #build()} has already been called.
+ */
+ public Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector) {
+ Assertions.checkState(!buildCalled);
+ this.analyticsCollector = analyticsCollector;
+ return this;
+ }
+
+ /**
+ * Sets whether media sources should be initialized lazily.
+ *
+ * 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.
+ *
+ * @param useLazyPreparation Whether to use lazy preparation.
+ * @return This builder.
+ * @throws IllegalStateException If {@link #build()} has already been called.
+ */
+ public Builder setUseLazyPreparation(boolean useLazyPreparation) {
+ Assertions.checkState(!buildCalled);
+ this.useLazyPreparation = useLazyPreparation;
+ return this;
+ }
+
/**
* Sets the {@link Clock} that will be used by the player. Should only be set for testing
* purposes.
diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
index ba63dee80e..b5956c9dae 100644
--- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
+++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
@@ -95,6 +95,7 @@ public class SimpleExoPlayer extends BasePlayer
private BandwidthMeter bandwidthMeter;
private AnalyticsCollector analyticsCollector;
private Looper looper;
+ private boolean useLazyPreparation;
private boolean buildCalled;
/**
@@ -115,6 +116,7 @@ public class SimpleExoPlayer extends BasePlayer
* Looper} of the application's main thread if the current thread doesn't have a {@link
* Looper}
*
{@link AnalyticsCollector}: {@link AnalyticsCollector} with {@link Clock#DEFAULT}
+ * {@code useLazyPreparation}: {@code true}
* {@link Clock}: {@link Clock#DEFAULT}
*
*
@@ -142,6 +144,7 @@ public class SimpleExoPlayer extends BasePlayer
DefaultBandwidthMeter.getSingletonInstance(context),
Util.getLooper(),
new AnalyticsCollector(Clock.DEFAULT),
+ /* useLazyPreparation= */ true,
Clock.DEFAULT);
}
@@ -160,6 +163,7 @@ public class SimpleExoPlayer extends BasePlayer
* @param bandwidthMeter A {@link BandwidthMeter}.
* @param looper A {@link Looper} that must be used for all calls to the player.
* @param analyticsCollector An {@link AnalyticsCollector}.
+ * @param useLazyPreparation Whether media sources should be initialized lazily.
* @param clock A {@link Clock}. Should always be {@link Clock#DEFAULT}.
*/
public Builder(
@@ -170,6 +174,7 @@ public class SimpleExoPlayer extends BasePlayer
BandwidthMeter bandwidthMeter,
Looper looper,
AnalyticsCollector analyticsCollector,
+ boolean useLazyPreparation,
Clock clock) {
this.context = context;
this.renderersFactory = renderersFactory;
@@ -178,6 +183,7 @@ public class SimpleExoPlayer extends BasePlayer
this.bandwidthMeter = bandwidthMeter;
this.looper = looper;
this.analyticsCollector = analyticsCollector;
+ this.useLazyPreparation = useLazyPreparation;
this.clock = clock;
}
@@ -247,6 +253,23 @@ public class SimpleExoPlayer extends BasePlayer
return this;
}
+ /**
+ * Sets whether media sources should be initialized lazily.
+ *
+ * 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.
+ *
+ * @param useLazyPreparation Whether to use lazy preparation.
+ * @return This builder.
+ * @throws IllegalStateException If {@link #build()} has already been called.
+ */
+ public Builder setUseLazyPreparation(boolean useLazyPreparation) {
+ Assertions.checkState(!buildCalled);
+ this.useLazyPreparation = useLazyPreparation;
+ return this;
+ }
+
/**
* Sets the {@link Clock} that will be used by the player. Should only be set for testing
* purposes.