From eee9b312dc367f7f70c609cb73d60f55fc8ff47c Mon Sep 17 00:00:00 2001 From: tonihei Date: Thu, 6 Aug 2020 18:54:58 +0100 Subject: [PATCH] Change default value of throwWhenStuckBuffering to true. This change caused no problems and can be enabled by default. PiperOrigin-RevId: 325264859 --- .../com/google/android/exoplayer2/ExoPlayer.java | 5 +++-- .../google/android/exoplayer2/ExoPlayerImpl.java | 6 +++--- .../android/exoplayer2/ExoPlayerImplInternal.java | 5 +++-- .../android/exoplayer2/SimpleExoPlayer.java | 5 +++-- .../google/android/exoplayer2/ExoPlayerTest.java | 6 ------ .../exoplayer2/testutil/TestExoPlayer.java | 15 --------------- 6 files changed, 12 insertions(+), 30 deletions(-) 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 85d40095ac..df572abf65 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 @@ -215,6 +215,7 @@ public interface ExoPlayer extends Player { useLazyPreparation = true; seekParameters = SeekParameters.DEFAULT; clock = Clock.DEFAULT; + throwWhenStuckBuffering = true; } /** @@ -411,8 +412,8 @@ public interface ExoPlayer extends Player { if (releaseTimeoutMs > 0) { player.experimental_setReleaseTimeoutMs(releaseTimeoutMs); } - if (throwWhenStuckBuffering) { - player.experimental_throwWhenStuckBuffering(); + if (!throwWhenStuckBuffering) { + player.experimental_disableThrowWhenStuckBuffering(); } return player; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index cf738ed71a..26c98cbe2b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -200,13 +200,13 @@ import java.util.concurrent.TimeoutException; } /** - * Configures the player to throw when it detects it's stuck buffering. + * Configures the player to not throw when it detects it's stuck buffering. * *

This method is experimental, and will be renamed or removed in a future release. It should * only be called before the player is used. */ - public void experimental_throwWhenStuckBuffering() { - internalPlayer.experimental_throwWhenStuckBuffering(); + public void experimental_disableThrowWhenStuckBuffering() { + internalPlayer.experimental_disableThrowWhenStuckBuffering(); } @Override diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 967e1a1562..65e05aa64c 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -224,6 +224,7 @@ import java.util.concurrent.atomic.AtomicBoolean; this.pauseAtEndOfWindow = pauseAtEndOfWindow; this.clock = clock; + throwWhenStuckBuffering = true; backBufferDurationUs = loadControl.getBackBufferDurationUs(); retainBackBufferFromKeyframe = loadControl.retainBackBufferFromKeyframe(); @@ -257,8 +258,8 @@ import java.util.concurrent.atomic.AtomicBoolean; this.releaseTimeoutMs = releaseTimeoutMs; } - public void experimental_throwWhenStuckBuffering() { - throwWhenStuckBuffering = true; + public void experimental_disableThrowWhenStuckBuffering() { + throwWhenStuckBuffering = false; } public void experimental_enableOffloadScheduling(boolean enableOffloadScheduling) { 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 281474893d..ab091cbd83 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 @@ -206,6 +206,7 @@ public class SimpleExoPlayer extends BasePlayer useLazyPreparation = true; seekParameters = SeekParameters.DEFAULT; clock = Clock.DEFAULT; + throwWhenStuckBuffering = true; } /** @@ -618,8 +619,8 @@ public class SimpleExoPlayer extends BasePlayer wifiLockManager = new WifiLockManager(builder.context); wifiLockManager.setEnabled(builder.wakeMode == C.WAKE_MODE_NETWORK); deviceInfo = createDeviceInfo(streamVolumeManager); - if (builder.throwWhenStuckBuffering) { - player.experimental_throwWhenStuckBuffering(); + if (!builder.throwWhenStuckBuffering) { + player.experimental_disableThrowWhenStuckBuffering(); } sendRendererMessage(C.TRACK_TYPE_AUDIO, Renderer.MSG_SET_AUDIO_ATTRIBUTES, audioAttributes); diff --git a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java index 20c6e66f6a..3c43d3c22f 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java @@ -115,7 +115,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentMatcher; @@ -4588,8 +4587,6 @@ public final class ExoPlayerTest { testRunner.blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS); } - // Disabled until the flag to throw exceptions for [internal: b/144538905] is enabled by default. - @Ignore @Test public void loadControlNeverWantsToLoad_throwsIllegalStateException() { LoadControl neverLoadingLoadControl = @@ -4697,7 +4694,6 @@ public final class ExoPlayerTest { new TestExoPlayer.Builder(context) .setRenderers(rendererWaitingForData) .setLoadControl(loadControlWithMaxBufferUs) - .experimental_setThrowWhenStuckBuffering(true) .build(); player.setMediaSource(mediaSourceWithLoadInProgress); player.prepare(); @@ -7334,8 +7330,6 @@ public final class ExoPlayerTest { assertThat(positionAfterPause.get()).isEqualTo(10_000); } - // Disabled until the flag to throw exceptions for [internal: b/144538905] is enabled by default. - @Ignore @Test public void infiniteLoading_withSmallAllocations_oomIsPreventedByLoadControl_andThrowsStuckBufferingIllegalStateException() { diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/TestExoPlayer.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/TestExoPlayer.java index 548c0a0ccf..5441d25cd9 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/TestExoPlayer.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/TestExoPlayer.java @@ -61,7 +61,6 @@ public class TestExoPlayer { @Nullable private Renderer[] renderers; @Nullable private RenderersFactory renderersFactory; private boolean useLazyPreparation; - private boolean throwWhenStuckBuffering; private @MonotonicNonNull Looper looper; public Builder(Context context) { @@ -231,19 +230,6 @@ public class TestExoPlayer { return looper; } - /** - * Sets whether the player should throw when it detects it's stuck buffering. - * - *

This method is experimental, and will be renamed or removed in a future release. - * - * @param throwWhenStuckBuffering Whether to throw when the player detects it's stuck buffering. - * @return This builder. - */ - public Builder experimental_setThrowWhenStuckBuffering(boolean throwWhenStuckBuffering) { - this.throwWhenStuckBuffering = throwWhenStuckBuffering; - return this; - } - /** * Builds an {@link SimpleExoPlayer} using the provided values or their defaults. * @@ -278,7 +264,6 @@ public class TestExoPlayer { .setClock(clock) .setUseLazyPreparation(useLazyPreparation) .setLooper(looper) - .experimental_setThrowWhenStuckBuffering(throwWhenStuckBuffering) .build(); } }