Do not reference AnalyticsCollector in common constructor

This prevents it to be stripped by R8 if a custom one is
passed.

#minor-release

PiperOrigin-RevId: 428034999
This commit is contained in:
krocard 2022-02-11 18:27:34 +00:00 committed by Ian Baker
parent 437e178ef8
commit 743a46e1b2
2 changed files with 8 additions and 11 deletions

View File

@ -16,7 +16,6 @@
package androidx.media3.exoplayer; package androidx.media3.exoplayer;
import static androidx.media3.common.util.Assertions.checkArgument; import static androidx.media3.common.util.Assertions.checkArgument;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import android.content.Context; import android.content.Context;
@ -65,6 +64,7 @@ import androidx.media3.exoplayer.video.VideoFrameMetadataListener;
import androidx.media3.exoplayer.video.spherical.CameraMotionListener; import androidx.media3.exoplayer.video.spherical.CameraMotionListener;
import androidx.media3.extractor.DefaultExtractorsFactory; import androidx.media3.extractor.DefaultExtractorsFactory;
import androidx.media3.extractor.ExtractorsFactory; import androidx.media3.extractor.ExtractorsFactory;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import java.util.List; import java.util.List;
@ -383,7 +383,7 @@ public interface ExoPlayer extends Player {
/* package */ Supplier<TrackSelector> trackSelectorSupplier; /* package */ Supplier<TrackSelector> trackSelectorSupplier;
/* package */ Supplier<LoadControl> loadControlSupplier; /* package */ Supplier<LoadControl> loadControlSupplier;
/* package */ Supplier<BandwidthMeter> bandwidthMeterSupplier; /* package */ Supplier<BandwidthMeter> bandwidthMeterSupplier;
/* package */ Supplier<AnalyticsCollector> analyticsCollectorSupplier; /* package */ Function<Clock, AnalyticsCollector> analyticsCollectorFunction;
/* package */ Looper looper; /* package */ Looper looper;
@Nullable /* package */ PriorityTaskManager priorityTaskManager; @Nullable /* package */ PriorityTaskManager priorityTaskManager;
/* package */ AudioAttributes audioAttributes; /* package */ AudioAttributes audioAttributes;
@ -547,7 +547,7 @@ public interface ExoPlayer extends Player {
() -> trackSelector, () -> trackSelector,
() -> loadControl, () -> loadControl,
() -> bandwidthMeter, () -> bandwidthMeter,
() -> analyticsCollector); (clock) -> analyticsCollector);
} }
private Builder( private Builder(
@ -561,7 +561,7 @@ public interface ExoPlayer extends Player {
() -> new DefaultTrackSelector(context), () -> new DefaultTrackSelector(context),
DefaultLoadControl::new, DefaultLoadControl::new,
() -> DefaultBandwidthMeter.getSingletonInstance(context), () -> DefaultBandwidthMeter.getSingletonInstance(context),
/* analyticsCollectorSupplier= */ null); DefaultAnalyticsCollector::new);
} }
private Builder( private Builder(
@ -571,17 +571,14 @@ public interface ExoPlayer extends Player {
Supplier<TrackSelector> trackSelectorSupplier, Supplier<TrackSelector> trackSelectorSupplier,
Supplier<LoadControl> loadControlSupplier, Supplier<LoadControl> loadControlSupplier,
Supplier<BandwidthMeter> bandwidthMeterSupplier, Supplier<BandwidthMeter> bandwidthMeterSupplier,
@Nullable Supplier<AnalyticsCollector> analyticsCollectorSupplier) { Function<Clock, AnalyticsCollector> analyticsCollectorFunction) {
this.context = context; this.context = context;
this.renderersFactorySupplier = renderersFactorySupplier; this.renderersFactorySupplier = renderersFactorySupplier;
this.mediaSourceFactorySupplier = mediaSourceFactorySupplier; this.mediaSourceFactorySupplier = mediaSourceFactorySupplier;
this.trackSelectorSupplier = trackSelectorSupplier; this.trackSelectorSupplier = trackSelectorSupplier;
this.loadControlSupplier = loadControlSupplier; this.loadControlSupplier = loadControlSupplier;
this.bandwidthMeterSupplier = bandwidthMeterSupplier; this.bandwidthMeterSupplier = bandwidthMeterSupplier;
this.analyticsCollectorSupplier = this.analyticsCollectorFunction = analyticsCollectorFunction;
analyticsCollectorSupplier != null
? analyticsCollectorSupplier
: () -> new DefaultAnalyticsCollector(checkNotNull(clock));
looper = Util.getCurrentOrMainLooper(); looper = Util.getCurrentOrMainLooper();
audioAttributes = AudioAttributes.DEFAULT; audioAttributes = AudioAttributes.DEFAULT;
wakeMode = C.WAKE_MODE_NONE; wakeMode = C.WAKE_MODE_NONE;
@ -708,7 +705,7 @@ public interface ExoPlayer extends Player {
@UnstableApi @UnstableApi
public Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector) { public Builder setAnalyticsCollector(AnalyticsCollector analyticsCollector) {
checkState(!buildCalled); checkState(!buildCalled);
this.analyticsCollectorSupplier = () -> analyticsCollector; this.analyticsCollectorFunction = (clock) -> analyticsCollector;
return this; return this;
} }

View File

@ -233,7 +233,7 @@ import java.util.concurrent.TimeoutException;
+ Util.DEVICE_DEBUG_INFO + Util.DEVICE_DEBUG_INFO
+ "]"); + "]");
applicationContext = builder.context.getApplicationContext(); applicationContext = builder.context.getApplicationContext();
analyticsCollector = builder.analyticsCollectorSupplier.get(); analyticsCollector = builder.analyticsCollectorFunction.apply(builder.clock);
priorityTaskManager = builder.priorityTaskManager; priorityTaskManager = builder.priorityTaskManager;
audioAttributes = builder.audioAttributes; audioAttributes = builder.audioAttributes;
videoScalingMode = builder.videoScalingMode; videoScalingMode = builder.videoScalingMode;