From b6f365263681bbc7c7e6a6fba1608292211433b1 Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Tue, 29 Mar 2022 15:21:39 +0300 Subject: [PATCH 1/9] Capture more errors from DRM session manager --- .../exoplayer/ReactExoplayerView.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 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 e4000116..3dbc0e20 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -564,6 +564,10 @@ class ReactExoplayerView extends FrameLayout implements return; } } + if (drmSessionManager == null) { + // DRM Session Manager failed to instantiate, no other work can be done - error has been handled by the instantiating method + return; + } // End DRM ArrayList mediaSourceList = buildTextSources(); @@ -608,26 +612,36 @@ class ReactExoplayerView extends FrameLayout implements } - private DrmSessionManager buildDrmSessionManager(UUID uuid, - String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException { + private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray, int retryCount) throws UnsupportedDrmException { if (Util.SDK_INT < 18) { return null; } - HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl, - buildHttpDataSourceFactory(false)); - if (keyRequestPropertiesArray != null) { - for (int i = 0; i < keyRequestPropertiesArray.length - 1; i += 2) { - drmCallback.setKeyRequestProperty(keyRequestPropertiesArray[i], - keyRequestPropertiesArray[i + 1]); + try { + HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl, + buildHttpDataSourceFactory(false)); + if (keyRequestPropertiesArray != null) { + for (int i = 0; i < keyRequestPropertiesArray.length - 1; i += 2) { + drmCallback.setKeyRequestProperty(keyRequestPropertiesArray[i], keyRequestPropertiesArray[i + 1]); + } } + FrameworkMediaDrm mediaDrm = FrameworkMediaDrm.newInstance(uuid); + if (hasDrmFailed) { + // When DRM fails using L1 we want to switch to L3 + mediaDrm.setPropertyString("securityLevel", "L3"); + } + return new DefaultDrmSessionManager(uuid, mediaDrm, drmCallback, null, false, 3); + } catch(UnsupportedDrmException e) { + // Unsupported DRM exceptions are handled by the calling method + throw e; + } catch (Exception e) { + if (retryCount < 3) { + // Attempt retry 3 times in case where the OS Media DRM Framework fails for whatever reason + return buildDrmSessionManager(uuid, licenseUrl, keyRequestPropertiesArray, ++retryCount); + } + // Handle the unknow exception and emit to JS + eventEmitter.error(ex.toString(), ex, "3006"); + return null; } - FrameworkMediaDrm mediaDrm = FrameworkMediaDrm.newInstance(uuid); - if (hasDrmFailed) { - // When DRM fails using L1 we want to switch to L3 - mediaDrm.setPropertyString("securityLevel", "L3"); - } - return new DefaultDrmSessionManager(uuid, - mediaDrm, drmCallback, null, false, 3); } private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessionManager drmSessionManager) { From 88f32ae3c8e8d21a24d67d39042016fdcf77b775 Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Wed, 30 Mar 2022 14:29:08 +0300 Subject: [PATCH 2/9] Move DRM init to a separate thread --- .../exoplayer/ReactExoplayerView.java | 127 +++++++++++------- 1 file changed, 79 insertions(+), 48 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 3dbc0e20..13eaca83 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -7,6 +7,7 @@ import android.content.Context; import android.media.AudioManager; import android.net.Uri; import android.os.Handler; +import android.os.Looper; import android.os.Message; import android.text.TextUtils; import android.util.Log; @@ -547,59 +548,33 @@ class ReactExoplayerView extends FrameLayout implements PlaybackParameters params = new PlaybackParameters(rate, 1f); player.setPlaybackParameters(params); } + if (playerNeedsSource && srcUri != null) { exoPlayerView.invalidateAspectRatio(); + // DRM session manager creation must be done on a different thread to prevent crashes so we start a new thread + ExecutorService es = Executors.newSingleThreadExecutor(); + es.execute(new Runnable() { + @Override + public void run() { + + // DRM initialization must run on a different thread + initializePlayerDrm(); + + // Initialize handler to run on the main thread + new Handler(Looper.getMainLooper()).post(new Runnable () { + @Override + public void run () { + // Source initialization must run on the main thread + initializePlayerSource(); + } + }); - // DRM - DrmSessionManager drmSessionManager = null; - if (self.drmUUID != null) { - try { - drmSessionManager = buildDrmSessionManager(self.drmUUID, self.drmLicenseUrl, - self.drmLicenseHeader); - } catch (UnsupportedDrmException e) { - int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported - : (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME - ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown); - eventEmitter.error(getResources().getString(errorStringId), e, "3003"); - return; } - } - if (drmSessionManager == null) { - // DRM Session Manager failed to instantiate, no other work can be done - error has been handled by the instantiating method - return; - } - // End DRM - - ArrayList mediaSourceList = buildTextSources(); - MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager); - MediaSource mediaSource; - if (mediaSourceList.size() == 0) { - mediaSource = videoSource; - } else { - mediaSourceList.add(0, videoSource); - MediaSource[] textSourceArray = mediaSourceList.toArray( - new MediaSource[mediaSourceList.size()] - ); - mediaSource = new MergingMediaSource(textSourceArray); - } - - boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; - if (haveResumePosition) { - player.seekTo(resumeWindow, resumePosition); - } - player.prepare(mediaSource, !haveResumePosition, false); - playerNeedsSource = false; - - reLayout(exoPlayerView); - eventEmitter.loadStart(); - loadVideoStarted = true; + }); + } else { + finishPlayerInitialization(); } - - // Initializing the playerControlView - initializePlayerControl(); - setControls(controls); - applyModifiers(); - startBufferCheckTimer(); + } catch (Exception ex) { self.playerNeedsSource = true; @@ -612,6 +587,62 @@ class ReactExoplayerView extends FrameLayout implements } + private void initializePlayerDrm() { + DrmSessionManager drmSessionManager = null; + if (self.drmUUID != null) { + try { + drmSessionManager = buildDrmSessionManager(self.drmUUID, self.drmLicenseUrl, + self.drmLicenseHeader); + } catch (UnsupportedDrmException e) { + int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported + : (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME + ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown); + eventEmitter.error(getResources().getString(errorStringId), e, "3003"); + return; + } + } + if (drmSessionManager == null) { + // DRM Session Manager failed to instantiate, no other work can be done - error has been handled by the instantiating method + return; + } + } + + private void initializePlayerSource() { + ArrayList mediaSourceList = buildTextSources(); + MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager); + MediaSource mediaSource; + if (mediaSourceList.size() == 0) { + mediaSource = videoSource; + } else { + mediaSourceList.add(0, videoSource); + MediaSource[] textSourceArray = mediaSourceList.toArray( + new MediaSource[mediaSourceList.size()] + ); + mediaSource = new MergingMediaSource(textSourceArray); + } + + boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; + if (haveResumePosition) { + player.seekTo(resumeWindow, resumePosition); + } + player.prepare(mediaSource, !haveResumePosition, false); + playerNeedsSource = false; + + reLayout(exoPlayerView); + eventEmitter.loadStart(); + loadVideoStarted = true; + + finishPlayerInitialization(); + } + + private void finishPlayerInitialization() { + // Initializing the playerControlView + initializePlayerControl(); + setControls(controls); + applyModifiers(); + startBufferCheckTimer(); + } + private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray, int retryCount) throws UnsupportedDrmException { if (Util.SDK_INT < 18) { return null; From 2f77765fe2ce4fbd33540596358cba625cd94b1a Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Wed, 30 Mar 2022 14:35:48 +0300 Subject: [PATCH 3/9] Clean up --- .../exoplayer/ReactExoplayerView.java | 85 ++++++++++--------- 1 file changed, 45 insertions(+), 40 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 13eaca83..98413ef5 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -512,41 +512,8 @@ class ReactExoplayerView extends FrameLayout implements public void run() { try { if (player == null) { - ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); - trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); - trackSelector.setParameters(trackSelector.buildUponParameters() - .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); - - DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); - RNVLoadControl loadControl = new RNVLoadControl( - allocator, - minBufferMs, - maxBufferMs, - bufferForPlaybackMs, - bufferForPlaybackAfterRebufferMs, - -1, - true, - backBufferDurationMs, - DefaultLoadControl.DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME - ); - DefaultRenderersFactory renderersFactory = - new DefaultRenderersFactory(getContext()) - .setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); - player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) - .setTrackSelector​(trackSelector) - .setBandwidthMeter(bandwidthMeter) - .setLoadControl(loadControl) - .build(); - player.addListener(self); - player.addMetadataOutput(self); - exoPlayerView.setPlayer(player); - audioBecomingNoisyReceiver.setListener(self); - bandwidthMeter.addEventListener(new Handler(), self); - setPlayWhenReady(!isPaused); - playerNeedsSource = true; - - PlaybackParameters params = new PlaybackParameters(rate, 1f); - player.setPlaybackParameters(params); + // Initialize core configuration and listeners + initializePlayerCore(self); } if (playerNeedsSource && srcUri != null) { @@ -558,21 +525,21 @@ class ReactExoplayerView extends FrameLayout implements public void run() { // DRM initialization must run on a different thread - initializePlayerDrm(); + initializePlayerDrm(self); // Initialize handler to run on the main thread new Handler(Looper.getMainLooper()).post(new Runnable () { @Override public void run () { // Source initialization must run on the main thread - initializePlayerSource(); + initializePlayerSource(self); } }); } }); } else { - finishPlayerInitialization(); + initializePlayerSource(self); } @@ -587,7 +554,45 @@ class ReactExoplayerView extends FrameLayout implements } - private void initializePlayerDrm() { + private void initializePlayerCore(ReactExoplayerView self) { + ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); + trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); + trackSelector.setParameters(trackSelector.buildUponParameters() + .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); + + DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); + RNVLoadControl loadControl = new RNVLoadControl( + allocator, + minBufferMs, + maxBufferMs, + bufferForPlaybackMs, + bufferForPlaybackAfterRebufferMs, + -1, + true, + backBufferDurationMs, + DefaultLoadControl.DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME + ); + DefaultRenderersFactory renderersFactory = + new DefaultRenderersFactory(getContext()) + .setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); + player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) + .setTrackSelector​(trackSelector) + .setBandwidthMeter(bandwidthMeter) + .setLoadControl(loadControl) + .build(); + player.addListener(self); + player.addMetadataOutput(self); + exoPlayerView.setPlayer(player); + audioBecomingNoisyReceiver.setListener(self); + bandwidthMeter.addEventListener(new Handler(), self); + setPlayWhenReady(!isPaused); + playerNeedsSource = true; + + PlaybackParameters params = new PlaybackParameters(rate, 1f); + player.setPlaybackParameters(params); + } + + private void initializePlayerDrm(ReactExoplayerView self) { DrmSessionManager drmSessionManager = null; if (self.drmUUID != null) { try { @@ -607,7 +612,7 @@ class ReactExoplayerView extends FrameLayout implements } } - private void initializePlayerSource() { + private void initializePlayerSource(ReactExoplayerView self) { ArrayList mediaSourceList = buildTextSources(); MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager); MediaSource mediaSource; From 142521bc0ec1e37b92cb2e2a8a8402c41f6aed8e Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Wed, 30 Mar 2022 14:43:04 +0300 Subject: [PATCH 4/9] Fix build issues --- .../exoplayer/ReactExoplayerView.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 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 98413ef5..2b0ee236 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -523,23 +523,24 @@ class ReactExoplayerView extends FrameLayout implements es.execute(new Runnable() { @Override public void run() { - // DRM initialization must run on a different thread - initializePlayerDrm(self); - + DRMSessionManager drmSessionManager = initializePlayerDrm(self); + if (drmSessionManager == null) { + // Failed to intialize DRM session manager - cannot continue + return; + } // Initialize handler to run on the main thread new Handler(Looper.getMainLooper()).post(new Runnable () { @Override public void run () { // Source initialization must run on the main thread - initializePlayerSource(self); + initializePlayerSource(self, drmSessionManager); } }); - } }); } else { - initializePlayerSource(self); + initializePlayerSource(self, null); } @@ -592,27 +593,24 @@ class ReactExoplayerView extends FrameLayout implements player.setPlaybackParameters(params); } - private void initializePlayerDrm(ReactExoplayerView self) { + private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) { DrmSessionManager drmSessionManager = null; if (self.drmUUID != null) { try { - drmSessionManager = buildDrmSessionManager(self.drmUUID, self.drmLicenseUrl, + drmSessionManager = self.buildDrmSessionManager(self.drmUUID, self.drmLicenseUrl, self.drmLicenseHeader); } catch (UnsupportedDrmException e) { int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported : (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown); eventEmitter.error(getResources().getString(errorStringId), e, "3003"); - return; + return null; } } - if (drmSessionManager == null) { - // DRM Session Manager failed to instantiate, no other work can be done - error has been handled by the instantiating method - return; - } + return drmSessionManager; } - private void initializePlayerSource(ReactExoplayerView self) { + private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager) { ArrayList mediaSourceList = buildTextSources(); MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager); MediaSource mediaSource; @@ -666,10 +664,10 @@ class ReactExoplayerView extends FrameLayout implements mediaDrm.setPropertyString("securityLevel", "L3"); } return new DefaultDrmSessionManager(uuid, mediaDrm, drmCallback, null, false, 3); - } catch(UnsupportedDrmException e) { + } catch(UnsupportedDrmException ex) { // Unsupported DRM exceptions are handled by the calling method - throw e; - } catch (Exception e) { + throw ex; + } catch (Exception ex) { if (retryCount < 3) { // Attempt retry 3 times in case where the OS Media DRM Framework fails for whatever reason return buildDrmSessionManager(uuid, licenseUrl, keyRequestPropertiesArray, ++retryCount); From cca274454269828d29352fa9526fa7983eeaf2a3 Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Wed, 30 Mar 2022 14:49:40 +0300 Subject: [PATCH 5/9] Fix typo --- .../java/com/brentvatne/exoplayer/ReactExoplayerView.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 2b0ee236..ea003623 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -524,7 +524,7 @@ class ReactExoplayerView extends FrameLayout implements @Override public void run() { // DRM initialization must run on a different thread - DRMSessionManager drmSessionManager = initializePlayerDrm(self); + DrmSessionManager drmSessionManager = initializePlayerDrm(self); if (drmSessionManager == null) { // Failed to intialize DRM session manager - cannot continue return; @@ -646,6 +646,10 @@ class ReactExoplayerView extends FrameLayout implements startBufferCheckTimer(); } + private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException { + return buildDrmSessionManager(uuid, licenseUrl, keyRequestPropertiesArray, 0); + } + private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray, int retryCount) throws UnsupportedDrmException { if (Util.SDK_INT < 18) { return null; From 7067afa609e6d7c4e801d0be446d06f082cf1f1c Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Wed, 30 Mar 2022 15:04:49 +0300 Subject: [PATCH 6/9] Fix runtime crash --- .../main/java/com/brentvatne/exoplayer/ReactExoplayerView.java | 3 +++ 1 file changed, 3 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 ea003623..18174c41 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -500,6 +500,9 @@ class ReactExoplayerView extends FrameLayout implements } private void stopBufferCheckTimer() { + if (this.bufferCheckTimer == null) { + return; + } this.bufferCheckTimer.cancel(); this.bufferCheckTimer = null; } From bd1f7f50cb48ebba526bdf6c2fad1e7230650d32 Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Wed, 30 Mar 2022 15:19:50 +0300 Subject: [PATCH 7/9] Fix runtime issues --- .../exoplayer/ReactExoplayerView.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 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 18174c41..4d8fd980 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -560,8 +560,8 @@ class ReactExoplayerView extends FrameLayout implements private void initializePlayerCore(ReactExoplayerView self) { ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); - trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); - trackSelector.setParameters(trackSelector.buildUponParameters() + self.trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); + self.trackSelector.setParameters(self.trackSelector.buildUponParameters() .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); @@ -579,21 +579,21 @@ class ReactExoplayerView extends FrameLayout implements DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()) .setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); - player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) + self.player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) .setTrackSelector​(trackSelector) .setBandwidthMeter(bandwidthMeter) .setLoadControl(loadControl) .build(); - player.addListener(self); - player.addMetadataOutput(self); - exoPlayerView.setPlayer(player); - audioBecomingNoisyReceiver.setListener(self); - bandwidthMeter.addEventListener(new Handler(), self); + self.player.addListener(self); + self.player.addMetadataOutput(self); + self.exoPlayerView.setPlayer(player); + self.audioBecomingNoisyReceiver.setListener(self); + self.bandwidthMeter.addEventListener(new Handler(), self); setPlayWhenReady(!isPaused); - playerNeedsSource = true; + self.playerNeedsSource = true; PlaybackParameters params = new PlaybackParameters(rate, 1f); - player.setPlaybackParameters(params); + self.player.setPlaybackParameters(params); } private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) { @@ -615,7 +615,7 @@ class ReactExoplayerView extends FrameLayout implements private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager) { ArrayList mediaSourceList = buildTextSources(); - MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager); + MediaSource videoSource = self.buildMediaSource(self.srcUri, self.extension, drmSessionManager); MediaSource mediaSource; if (mediaSourceList.size() == 0) { mediaSource = videoSource; From edd3cc169819c7ce8c457fececd569fd52977d08 Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Wed, 30 Mar 2022 15:27:09 +0300 Subject: [PATCH 8/9] Fix runtime issues --- .../java/com/brentvatne/exoplayer/ReactExoplayerView.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 4d8fd980..759989ef 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -537,13 +537,13 @@ class ReactExoplayerView extends FrameLayout implements @Override public void run () { // Source initialization must run on the main thread - initializePlayerSource(self, drmSessionManager); + initializePlayerSource(self, drmSessionManager, srcUri); } }); } }); } else { - initializePlayerSource(self, null); + initializePlayerSource(self, null, srcUri); } @@ -613,9 +613,9 @@ class ReactExoplayerView extends FrameLayout implements return drmSessionManager; } - private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager) { + private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager, Uri srcUri) { ArrayList mediaSourceList = buildTextSources(); - MediaSource videoSource = self.buildMediaSource(self.srcUri, self.extension, drmSessionManager); + MediaSource videoSource = self.buildMediaSource(srcUri, self.extension, drmSessionManager); MediaSource mediaSource; if (mediaSourceList.size() == 0) { mediaSource = videoSource; From 0e3fe11b7885ee2ab63dfa86c3b2caac7ff40c73 Mon Sep 17 00:00:00 2001 From: Armands Malejevs Date: Wed, 30 Mar 2022 15:33:17 +0300 Subject: [PATCH 9/9] Fix runtime issues --- .../exoplayer/ReactExoplayerView.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 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 759989ef..2022c108 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -537,13 +537,13 @@ class ReactExoplayerView extends FrameLayout implements @Override public void run () { // Source initialization must run on the main thread - initializePlayerSource(self, drmSessionManager, srcUri); + initializePlayerSource(self, drmSessionManager); } }); } }); - } else { - initializePlayerSource(self, null, srcUri); + } else if (srcUri != null) { + initializePlayerSource(self, null); } @@ -560,8 +560,8 @@ class ReactExoplayerView extends FrameLayout implements private void initializePlayerCore(ReactExoplayerView self) { ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); - self.trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); - self.trackSelector.setParameters(self.trackSelector.buildUponParameters() + trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); + trackSelector.setParameters(trackSelector.buildUponParameters() .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); @@ -579,21 +579,21 @@ class ReactExoplayerView extends FrameLayout implements DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext()) .setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); - self.player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) + player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) .setTrackSelector​(trackSelector) .setBandwidthMeter(bandwidthMeter) .setLoadControl(loadControl) .build(); - self.player.addListener(self); - self.player.addMetadataOutput(self); - self.exoPlayerView.setPlayer(player); - self.audioBecomingNoisyReceiver.setListener(self); - self.bandwidthMeter.addEventListener(new Handler(), self); + player.addListener(self); + player.addMetadataOutput(self); + exoPlayerView.setPlayer(player); + audioBecomingNoisyReceiver.setListener(self); + bandwidthMeter.addEventListener(new Handler(), self); setPlayWhenReady(!isPaused); - self.playerNeedsSource = true; + playerNeedsSource = true; PlaybackParameters params = new PlaybackParameters(rate, 1f); - self.player.setPlaybackParameters(params); + player.setPlaybackParameters(params); } private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) { @@ -613,9 +613,9 @@ class ReactExoplayerView extends FrameLayout implements return drmSessionManager; } - private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager, Uri srcUri) { + private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager) { ArrayList mediaSourceList = buildTextSources(); - MediaSource videoSource = self.buildMediaSource(srcUri, self.extension, drmSessionManager); + MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager); MediaSource mediaSource; if (mediaSourceList.size() == 0) { mediaSource = videoSource;