From b274541431bae8a453a6e24111058edb235d6474 Mon Sep 17 00:00:00 2001 From: Gabriel Rivero Date: Thu, 28 Apr 2022 20:17:59 -0400 Subject: [PATCH] VEX-7093: Protect initialization of DRM (#29) This PR will fix the crash from the experiment on react-native-video Jira: VEX-7093 velocity PR: crunchyroll/velocity#2443 The crash was caused by using the player object before it was set by another thread, the change simply waits for the player to be available before executing any player interaction after DRM initialization. Reviews Major reviewer (domain expert): @jctorresM Minor reviewer: @jacob-livingston --- .../com/brentvatne/exoplayer/ReactExoplayerView.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 15526b27..7d7a7c0e 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -632,6 +632,16 @@ class ReactExoplayerView extends FrameLayout implements mediaSource = new MergingMediaSource(textSourceArray); } + // wait for player to be set + while (player == null) { + try { + wait(); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + Log.e("ExoPlayer Exception", ex.toString()); + } + } + boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { player.seekTo(resumeWindow, resumePosition);