Commit ebf8dc99 by tonihei Committed by Toni

Extend ExoPlayer builders with useLazyPreparations and AnalyticsCollector.

Both values are needed to set-up the ExoPlayer instances for playlists.

PiperOrigin-RevId: 264146052
parent 17d8e372
...@@ -19,6 +19,7 @@ import android.content.Context; ...@@ -19,6 +19,7 @@ import android.content.Context;
import android.os.Looper; import android.os.Looper;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer; import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer;
import com.google.android.exoplayer2.metadata.MetadataRenderer; import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.source.ClippingMediaSource; import com.google.android.exoplayer2.source.ClippingMediaSource;
...@@ -138,6 +139,8 @@ public interface ExoPlayer extends Player { ...@@ -138,6 +139,8 @@ public interface ExoPlayer extends Player {
private LoadControl loadControl; private LoadControl loadControl;
private BandwidthMeter bandwidthMeter; private BandwidthMeter bandwidthMeter;
private Looper looper; private Looper looper;
private AnalyticsCollector analyticsCollector;
private boolean useLazyPreparation;
private boolean buildCalled; private boolean buildCalled;
/** /**
...@@ -152,6 +155,8 @@ public interface ExoPlayer extends Player { ...@@ -152,6 +155,8 @@ public interface ExoPlayer extends Player {
* <li>{@link Looper}: The {@link Looper} associated with the current thread, or the {@link * <li>{@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} of the application's main thread if the current thread doesn't have a {@link
* Looper} * Looper}
* <li>{@link AnalyticsCollector}: {@link AnalyticsCollector} with {@link Clock#DEFAULT}
* <li>{@code useLazyPreparation}: {@code true}
* <li>{@link Clock}: {@link Clock#DEFAULT} * <li>{@link Clock}: {@link Clock#DEFAULT}
* </ul> * </ul>
* *
...@@ -165,6 +170,8 @@ public interface ExoPlayer extends Player { ...@@ -165,6 +170,8 @@ public interface ExoPlayer extends Player {
new DefaultLoadControl(), new DefaultLoadControl(),
DefaultBandwidthMeter.getSingletonInstance(context), DefaultBandwidthMeter.getSingletonInstance(context),
Util.getLooper(), Util.getLooper(),
new AnalyticsCollector(Clock.DEFAULT),
/* useLazyPreparation= */ true,
Clock.DEFAULT); Clock.DEFAULT);
} }
...@@ -180,6 +187,8 @@ public interface ExoPlayer extends Player { ...@@ -180,6 +187,8 @@ public interface ExoPlayer extends Player {
* @param loadControl A {@link LoadControl}. * @param loadControl A {@link LoadControl}.
* @param bandwidthMeter A {@link BandwidthMeter}. * @param bandwidthMeter A {@link BandwidthMeter}.
* @param looper A {@link Looper} that must be used for all calls to the player. * @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}. * @param clock A {@link Clock}. Should always be {@link Clock#DEFAULT}.
*/ */
public Builder( public Builder(
...@@ -188,6 +197,8 @@ public interface ExoPlayer extends Player { ...@@ -188,6 +197,8 @@ public interface ExoPlayer extends Player {
LoadControl loadControl, LoadControl loadControl,
BandwidthMeter bandwidthMeter, BandwidthMeter bandwidthMeter,
Looper looper, Looper looper,
AnalyticsCollector analyticsCollector,
boolean useLazyPreparation,
Clock clock) { Clock clock) {
Assertions.checkArgument(renderers.length > 0); Assertions.checkArgument(renderers.length > 0);
this.renderers = renderers; this.renderers = renderers;
...@@ -195,6 +206,8 @@ public interface ExoPlayer extends Player { ...@@ -195,6 +206,8 @@ public interface ExoPlayer extends Player {
this.loadControl = loadControl; this.loadControl = loadControl;
this.bandwidthMeter = bandwidthMeter; this.bandwidthMeter = bandwidthMeter;
this.looper = looper; this.looper = looper;
this.analyticsCollector = analyticsCollector;
this.useLazyPreparation = useLazyPreparation;
this.clock = clock; this.clock = clock;
} }
...@@ -252,6 +265,36 @@ public interface ExoPlayer extends Player { ...@@ -252,6 +265,36 @@ public interface ExoPlayer extends Player {
} }
/** /**
* 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.
*
* <p>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 * Sets the {@link Clock} that will be used by the player. Should only be set for testing
* purposes. * purposes.
* *
......
...@@ -95,6 +95,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -95,6 +95,7 @@ public class SimpleExoPlayer extends BasePlayer
private BandwidthMeter bandwidthMeter; private BandwidthMeter bandwidthMeter;
private AnalyticsCollector analyticsCollector; private AnalyticsCollector analyticsCollector;
private Looper looper; private Looper looper;
private boolean useLazyPreparation;
private boolean buildCalled; private boolean buildCalled;
/** /**
...@@ -115,6 +116,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -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} of the application's main thread if the current thread doesn't have a {@link
* Looper} * Looper}
* <li>{@link AnalyticsCollector}: {@link AnalyticsCollector} with {@link Clock#DEFAULT} * <li>{@link AnalyticsCollector}: {@link AnalyticsCollector} with {@link Clock#DEFAULT}
* <li>{@code useLazyPreparation}: {@code true}
* <li>{@link Clock}: {@link Clock#DEFAULT} * <li>{@link Clock}: {@link Clock#DEFAULT}
* </ul> * </ul>
* *
...@@ -142,6 +144,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -142,6 +144,7 @@ public class SimpleExoPlayer extends BasePlayer
DefaultBandwidthMeter.getSingletonInstance(context), DefaultBandwidthMeter.getSingletonInstance(context),
Util.getLooper(), Util.getLooper(),
new AnalyticsCollector(Clock.DEFAULT), new AnalyticsCollector(Clock.DEFAULT),
/* useLazyPreparation= */ true,
Clock.DEFAULT); Clock.DEFAULT);
} }
...@@ -160,6 +163,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -160,6 +163,7 @@ public class SimpleExoPlayer extends BasePlayer
* @param bandwidthMeter A {@link BandwidthMeter}. * @param bandwidthMeter A {@link BandwidthMeter}.
* @param looper A {@link Looper} that must be used for all calls to the player. * @param looper A {@link Looper} that must be used for all calls to the player.
* @param analyticsCollector An {@link AnalyticsCollector}. * @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}. * @param clock A {@link Clock}. Should always be {@link Clock#DEFAULT}.
*/ */
public Builder( public Builder(
...@@ -170,6 +174,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -170,6 +174,7 @@ public class SimpleExoPlayer extends BasePlayer
BandwidthMeter bandwidthMeter, BandwidthMeter bandwidthMeter,
Looper looper, Looper looper,
AnalyticsCollector analyticsCollector, AnalyticsCollector analyticsCollector,
boolean useLazyPreparation,
Clock clock) { Clock clock) {
this.context = context; this.context = context;
this.renderersFactory = renderersFactory; this.renderersFactory = renderersFactory;
...@@ -178,6 +183,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -178,6 +183,7 @@ public class SimpleExoPlayer extends BasePlayer
this.bandwidthMeter = bandwidthMeter; this.bandwidthMeter = bandwidthMeter;
this.looper = looper; this.looper = looper;
this.analyticsCollector = analyticsCollector; this.analyticsCollector = analyticsCollector;
this.useLazyPreparation = useLazyPreparation;
this.clock = clock; this.clock = clock;
} }
...@@ -248,6 +254,23 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -248,6 +254,23 @@ public class SimpleExoPlayer extends BasePlayer
} }
/** /**
* Sets whether media sources should be initialized lazily.
*
* <p>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 * Sets the {@link Clock} that will be used by the player. Should only be set for testing
* purposes. * purposes.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment