From 506aa2c9996391eb83b3b3affcb2be1a6d1dc5a2 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Mon, 30 Jan 2023 19:09:44 +0000 Subject: [PATCH] Instantiate `SurfaceView` on main thread On some devices/builds it seems that the `SurfaceView` constructor tries to create a handler. Move instantiation to the main thread when getting the debug surface view so that handler creation succeeds. PiperOrigin-RevId: 505745387 --- .../exoplayer2/transformerdemo/TransformerActivity.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java b/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java index 59ffd6d6fd..fcf7352c0d 100644 --- a/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java +++ b/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java @@ -738,9 +738,9 @@ public final class TransformerActivity extends AppCompatActivity { // Update the UI on the main thread and wait for the output surface to be available. CountDownLatch surfaceCreatedCountDownLatch = new CountDownLatch(1); - SurfaceView surfaceView = new SurfaceView(/* context= */ TransformerActivity.this); runOnUiThread( () -> { + surfaceView = new SurfaceView(/* context= */ TransformerActivity.this); AspectRatioFrameLayout debugFrame = checkNotNull(TransformerActivity.this.debugFrame); debugFrame.addView(surfaceView); debugFrame.setAspectRatio((float) width / height); @@ -772,7 +772,6 @@ public final class TransformerActivity extends AppCompatActivity { Thread.currentThread().interrupt(); return null; } - this.surfaceView = surfaceView; return surfaceView; } }