Commit 2b582b54 by ibaker Committed by Andrew Lewis

Add thread names to the 'player accessed on wrong thread' message

This will help app developers identify which thread is being used and
which is expected.

PiperOrigin-RevId: 370409697
parent 2a0b45ac
......@@ -588,9 +588,6 @@ public class SimpleExoPlayer extends BasePlayer
}
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;
......@@ -2014,13 +2011,18 @@ public class SimpleExoPlayer extends BasePlayer
// the app thread until the constructor finished executing.
constructorFinished.blockUninterruptible();
if (Looper.myLooper() != getApplicationLooper()) {
String message =
Util.formatInvariant(
"Player is accessed on the wrong thread.\n"
+ "Current thread: '%s'\n"
+ "Expected thread: '%s'\n"
+ "See https://exoplayer.dev/issues/player-accessed-on-wrong-thread",
Looper.myLooper().getThread().getName(),
getApplicationLooper().getThread().getName());
if (throwsWhenUsingWrongThread) {
throw new IllegalStateException(WRONG_THREAD_ERROR_MESSAGE);
throw new IllegalStateException(message);
}
Log.w(
TAG,
WRONG_THREAD_ERROR_MESSAGE,
hasNotifiedFullWrongThreadWarning ? null : new IllegalStateException());
Log.w(TAG, message, hasNotifiedFullWrongThreadWarning ? null : new IllegalStateException());
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