mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix NPE in AdaptiveBitrateTest due to missing Looper.
The new TestExoPlayer.Builder asserts that a Looper is present in the constructor, although it can be set later for cases where no such Looper exists. PiperOrigin-RevId: 306403491
This commit is contained in:
parent
af81238c92
commit
76ad0bc4ff
1 changed files with 13 additions and 3 deletions
|
|
@ -41,6 +41,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities to write unit/integration tests with a SimpleExoPlayer instance that uses fake
|
* Utilities to write unit/integration tests with a SimpleExoPlayer instance that uses fake
|
||||||
|
|
@ -77,7 +78,7 @@ public class TestExoPlayer {
|
||||||
@Nullable private Renderer[] renderers;
|
@Nullable private Renderer[] renderers;
|
||||||
@Nullable private RenderersFactory renderersFactory;
|
@Nullable private RenderersFactory renderersFactory;
|
||||||
private boolean useLazyPreparation;
|
private boolean useLazyPreparation;
|
||||||
private Looper looper;
|
private @MonotonicNonNull Looper looper;
|
||||||
|
|
||||||
public Builder(Context context) {
|
public Builder(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
@ -85,7 +86,10 @@ public class TestExoPlayer {
|
||||||
trackSelector = new DefaultTrackSelector(context);
|
trackSelector = new DefaultTrackSelector(context);
|
||||||
loadControl = new DefaultLoadControl();
|
loadControl = new DefaultLoadControl();
|
||||||
bandwidthMeter = new DefaultBandwidthMeter.Builder(context).build();
|
bandwidthMeter = new DefaultBandwidthMeter.Builder(context).build();
|
||||||
looper = Assertions.checkNotNull(Looper.myLooper());
|
@Nullable Looper myLooper = Looper.myLooper();
|
||||||
|
if (myLooper != null) {
|
||||||
|
looper = myLooper;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -234,7 +238,11 @@ public class TestExoPlayer {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@link Looper} that will be used by the player. */
|
/**
|
||||||
|
* Returns the {@link Looper} that will be used by the player, or null if no {@link Looper} has
|
||||||
|
* been set yet and no default is available.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
public Looper getLooper() {
|
public Looper getLooper() {
|
||||||
return looper;
|
return looper;
|
||||||
}
|
}
|
||||||
|
|
@ -245,6 +253,8 @@ public class TestExoPlayer {
|
||||||
* @return The built {@link ExoPlayerTestRunner}.
|
* @return The built {@link ExoPlayerTestRunner}.
|
||||||
*/
|
*/
|
||||||
public SimpleExoPlayer build() {
|
public SimpleExoPlayer build() {
|
||||||
|
Assertions.checkNotNull(
|
||||||
|
looper, "TestExoPlayer builder run on a thread without Looper and no Looper specified.");
|
||||||
// Do not update renderersFactory and renderers here, otherwise their getters may
|
// Do not update renderersFactory and renderers here, otherwise their getters may
|
||||||
// return different values before and after build() is called, making them confusing.
|
// return different values before and after build() is called, making them confusing.
|
||||||
RenderersFactory playerRenderersFactory = renderersFactory;
|
RenderersFactory playerRenderersFactory = renderersFactory;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue