From c584022d34a3b4413482c47890e1cd20d28a801f Mon Sep 17 00:00:00 2001 From: Armands Malejev Date: Fri, 6 May 2022 00:10:55 +0300 Subject: [PATCH] VEX-7094: Android: Crash in ReactExoplayerView.java Line 694 (#30) When moving init logic to a different thread we missed one function that was not captured if an error occurred. This PR wraps the source init function that happens on a different thread in a try/catch to capture any errors that occur. --- .../brentvatne/exoplayer/ReactExoplayerView.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index fcddb28c..931bc9fe 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -540,8 +540,15 @@ class ReactExoplayerView extends FrameLayout implements // Initialize handler to run on the main thread activity.runOnUiThread(new Runnable() { public void run() { - // Source initialization must run on the main thread - initializePlayerSource(self, drmSessionManager); + try { + // Source initialization must run on the main thread + initializePlayerSource(self, drmSessionManager); + } catch (Exception ex) { + self.playerNeedsSource = true; + Log.e("ExoPlayer Exception", "Failed to initialize Player!"); + Log.e("ExoPlayer Exception", ex.toString()); + self.eventEmitter.error(ex.toString(), ex, "1001"); + } } }); } @@ -620,7 +627,7 @@ class ReactExoplayerView extends FrameLayout implements private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager) { ArrayList mediaSourceList = buildTextSources(); - MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager); + MediaSource videoSource = buildMediaSource(self.srcUri, self.extension, drmSessionManager); MediaSource mediaSource; if (mediaSourceList.size() == 0) { mediaSource = videoSource;