Commit c9ff3ef6 by tonihei Committed by Oliver Woodman

Create opt-in to throw when Player is accessed on wrong thread.

This allows users to verify their own usage before the default
value is changed to an opt-out.

issue:#4463
PiperOrigin-RevId: 308808722
parent de7c2c36
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
### dev-v2 (not yet released) ### dev-v2 (not yet released)
* Core library: * Core library:
* Add opt-in to verify correct thread usage with
`SimpleExoPlayer.setThrowsWhenUsingWrongThread(true)`
([#4463](https://github.com/google/ExoPlayer/issues/4463)).
* Add playbackPositionUs parameter to 'LoadControl.shouldContinueLoading'. * Add playbackPositionUs parameter to 'LoadControl.shouldContinueLoading'.
* The `DefaultLoadControl` default minimum buffer is set to 50 seconds, * The `DefaultLoadControl` default minimum buffer is set to 50 seconds,
equal to the default maximum buffer. `DefaultLoadControl` applies the equal to the default maximum buffer. `DefaultLoadControl` applies the
......
...@@ -336,6 +336,9 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -336,6 +336,9 @@ public class SimpleExoPlayer extends BasePlayer
} }
private static final String TAG = "SimpleExoPlayer"; private static final String TAG = "SimpleExoPlayer";
private static final String WRONG_THREAD_ERROR_MESSAGE =
"Player is accessed on the wrong thread. See "
+ "https://exoplayer.dev/issues/player-accessed-on-wrong-thread";
protected final Renderer[] renderers; protected final Renderer[] renderers;
...@@ -379,6 +382,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -379,6 +382,7 @@ public class SimpleExoPlayer extends BasePlayer
private List<Cue> currentCues; private List<Cue> currentCues;
@Nullable private VideoFrameMetadataListener videoFrameMetadataListener; @Nullable private VideoFrameMetadataListener videoFrameMetadataListener;
@Nullable private CameraMotionListener cameraMotionListener; @Nullable private CameraMotionListener cameraMotionListener;
private boolean throwsWhenUsingWrongThread;
private boolean hasNotifiedFullWrongThreadWarning; private boolean hasNotifiedFullWrongThreadWarning;
@Nullable private PriorityTaskManager priorityTaskManager; @Nullable private PriorityTaskManager priorityTaskManager;
private boolean isPriorityTaskManagerRegistered; private boolean isPriorityTaskManagerRegistered;
...@@ -1822,6 +1826,18 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -1822,6 +1826,18 @@ public class SimpleExoPlayer extends BasePlayer
streamVolumeManager.setMuted(muted); streamVolumeManager.setMuted(muted);
} }
/**
* Sets whether the player should throw an {@link IllegalStateException} when methods are called
* from a thread other than the one associated with {@link #getApplicationLooper()}.
*
* <p>The default is {@code false}, but will change to {@code true} in the future.
*
* @param throwsWhenUsingWrongThread Whether to throw when methods are called from a wrong thread.
*/
public void setThrowsWhenUsingWrongThread(boolean throwsWhenUsingWrongThread) {
this.throwsWhenUsingWrongThread = throwsWhenUsingWrongThread;
}
// Internal methods. // Internal methods.
private void removeSurfaceCallbacks() { private void removeSurfaceCallbacks() {
...@@ -1968,10 +1984,12 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -1968,10 +1984,12 @@ public class SimpleExoPlayer extends BasePlayer
private void verifyApplicationThread() { private void verifyApplicationThread() {
if (Looper.myLooper() != getApplicationLooper()) { if (Looper.myLooper() != getApplicationLooper()) {
if (throwsWhenUsingWrongThread) {
throw new IllegalStateException(WRONG_THREAD_ERROR_MESSAGE);
}
Log.w( Log.w(
TAG, TAG,
"Player is accessed on the wrong thread. See " WRONG_THREAD_ERROR_MESSAGE,
+ "https://exoplayer.dev/issues/player-accessed-on-wrong-thread",
hasNotifiedFullWrongThreadWarning ? null : new IllegalStateException()); hasNotifiedFullWrongThreadWarning ? null : new IllegalStateException());
hasNotifiedFullWrongThreadWarning = true; hasNotifiedFullWrongThreadWarning = true;
} }
......
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