From 3e3532691ad42a53b9136fd52eb7f9a578e21b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E7=91=BE=E7=91=9C?= <1009943858@qq.com> Date: Thu, 18 Apr 2024 16:18:14 +0800 Subject: [PATCH] fix(android): catch errors in `performOnPlayerView` (#3685) Co-authored-by: JinYuSha0 --- .../brentvatne/react/VideoManagerModule.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/VideoManagerModule.kt b/android/src/main/java/com/brentvatne/react/VideoManagerModule.kt index e3adcd50..58c75985 100644 --- a/android/src/main/java/com/brentvatne/react/VideoManagerModule.kt +++ b/android/src/main/java/com/brentvatne/react/VideoManagerModule.kt @@ -18,16 +18,20 @@ class VideoManagerModule(reactContext: ReactApplicationContext?) : ReactContextB private fun performOnPlayerView(reactTag: Int, callback: (ReactExoplayerView?) -> Unit) { UiThreadUtil.runOnUiThread { - val uiManager = UIManagerHelper.getUIManager( - reactApplicationContext, - if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) UIManagerType.FABRIC else UIManagerType.DEFAULT - ) + try { + val uiManager = UIManagerHelper.getUIManager( + reactApplicationContext, + if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) UIManagerType.FABRIC else UIManagerType.DEFAULT + ) - val view = uiManager?.resolveView(reactTag) + val view = uiManager?.resolveView(reactTag) - if (view is ReactExoplayerView) { - callback(view) - } else { + if (view is ReactExoplayerView) { + callback(view) + } else { + callback(null) + } + } catch (e: Exception) { callback(null) } }