Fix runtime issues

This commit is contained in:
Armands Malejevs 2022-03-30 15:33:17 +03:00
parent edd3cc1698
commit 0e3fe11b78

View File

@ -537,13 +537,13 @@ class ReactExoplayerView extends FrameLayout implements
@Override @Override
public void run () { public void run () {
// Source initialization must run on the main thread // Source initialization must run on the main thread
initializePlayerSource(self, drmSessionManager, srcUri); initializePlayerSource(self, drmSessionManager);
} }
}); });
} }
}); });
} else { } else if (srcUri != null) {
initializePlayerSource(self, null, srcUri); initializePlayerSource(self, null);
} }
@ -560,8 +560,8 @@ class ReactExoplayerView extends FrameLayout implements
private void initializePlayerCore(ReactExoplayerView self) { private void initializePlayerCore(ReactExoplayerView self) {
ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
self.trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
self.trackSelector.setParameters(self.trackSelector.buildUponParameters() trackSelector.setParameters(trackSelector.buildUponParameters()
.setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate)); .setMaxVideoBitrate(maxBitRate == 0 ? Integer.MAX_VALUE : maxBitRate));
DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE); DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
@ -579,21 +579,21 @@ class ReactExoplayerView extends FrameLayout implements
DefaultRenderersFactory renderersFactory = DefaultRenderersFactory renderersFactory =
new DefaultRenderersFactory(getContext()) new DefaultRenderersFactory(getContext())
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); .setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
self.player = new SimpleExoPlayer.Builder(getContext(), renderersFactory) player = new SimpleExoPlayer.Builder(getContext(), renderersFactory)
.setTrackSelector(trackSelector) .setTrackSelector(trackSelector)
.setBandwidthMeter(bandwidthMeter) .setBandwidthMeter(bandwidthMeter)
.setLoadControl(loadControl) .setLoadControl(loadControl)
.build(); .build();
self.player.addListener(self); player.addListener(self);
self.player.addMetadataOutput(self); player.addMetadataOutput(self);
self.exoPlayerView.setPlayer(player); exoPlayerView.setPlayer(player);
self.audioBecomingNoisyReceiver.setListener(self); audioBecomingNoisyReceiver.setListener(self);
self.bandwidthMeter.addEventListener(new Handler(), self); bandwidthMeter.addEventListener(new Handler(), self);
setPlayWhenReady(!isPaused); setPlayWhenReady(!isPaused);
self.playerNeedsSource = true; playerNeedsSource = true;
PlaybackParameters params = new PlaybackParameters(rate, 1f); PlaybackParameters params = new PlaybackParameters(rate, 1f);
self.player.setPlaybackParameters(params); player.setPlaybackParameters(params);
} }
private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) { private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) {
@ -613,9 +613,9 @@ class ReactExoplayerView extends FrameLayout implements
return drmSessionManager; return drmSessionManager;
} }
private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager, Uri srcUri) { private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager) {
ArrayList<MediaSource> mediaSourceList = buildTextSources(); ArrayList<MediaSource> mediaSourceList = buildTextSources();
MediaSource videoSource = self.buildMediaSource(srcUri, self.extension, drmSessionManager); MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager);
MediaSource mediaSource; MediaSource mediaSource;
if (mediaSourceList.size() == 0) { if (mediaSourceList.size() == 0) {
mediaSource = videoSource; mediaSource = videoSource;