From c193fe873efbb1d05339336e51f3682eeb910231 Mon Sep 17 00:00:00 2001 From: Armands Malejev Date: Tue, 10 May 2022 00:53:09 +0300 Subject: [PATCH] VEX-7095: Crash in ReactExoplayerView.java Line 1059 (#31) Prevent crashing when the track selector is null. --- .../com/brentvatne/exoplayer/ReactExoplayerView.java | 11 ++++++++--- 1 file changed, 8 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 931bc9fe..5b770d9c 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -571,8 +571,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(trackSelector.buildUponParameters() .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); @@ -591,7 +591,7 @@ class ReactExoplayerView extends FrameLayout implements new DefaultRenderersFactory(getContext()) .setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) - .setTrackSelector​(trackSelector) + .setTrackSelector​(self.trackSelector) .setBandwidthMeter(bandwidthMeter) .setLoadControl(loadControl) .build(); @@ -1042,6 +1042,11 @@ class ReactExoplayerView extends FrameLayout implements private WritableArray getAudioTrackInfo() { WritableArray audioTracks = Arguments.createArray(); + if (trackSelector == null) { + // Likely player is unmounting so no audio tracks are available anymore + return audioTracks; + } + MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo(); int index = getTrackRendererIndex(C.TRACK_TYPE_AUDIO); if (info == null || index == C.INDEX_UNSET) {