From 59f77ac83117c33f968bda078a78c6f41f8c39ec Mon Sep 17 00:00:00 2001 From: chrisk325 Date: Sun, 4 Jan 2026 16:17:16 +0530 Subject: [PATCH] optimisations for exo --- .../com/brentvatne/exoplayer/ReactExoplayerView.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/node_modules/react-native-video/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/node_modules/react-native-video/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index cb6f869..a939148 100644 --- a/node_modules/react-native-video/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/node_modules/react-native-video/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -270,6 +270,7 @@ public class ReactExoplayerView extends FrameLayout implements private final String instanceId = String.valueOf(UUID.randomUUID()); private CmcdConfiguration.Factory cmcdConfigurationFactory; + private static final ExecutorService SHARED_EXECUTOR = Executors.newSingleThreadExecutor(); public void setCmcdConfigurationFactory(CmcdConfiguration.Factory factory) { this.cmcdConfigurationFactory = factory; @@ -683,8 +684,7 @@ public class ReactExoplayerView extends FrameLayout implements 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(() -> { + SHARED_EXECUTOR.execute(() -> { // DRM initialization must run on a different thread if (viewHasDropped && runningSource == source) { return; @@ -1518,8 +1518,7 @@ public class ReactExoplayerView extends FrameLayout implements ArrayList textTracks = getTextTrackInfo(); if (source.getContentStartTime() != -1) { - ExecutorService es = Executors.newSingleThreadExecutor(); - es.execute(() -> { + SHARED_EXECUTOR.execute(() -> { // To prevent ANRs caused by getVideoTrackInfo we run this on a different thread // and notify the player only when we're done ArrayList videoTracks = getVideoTrackInfoFromManifest(); @@ -1632,12 +1631,11 @@ public class ReactExoplayerView extends FrameLayout implements // conditions @WorkerThread private ArrayList getVideoTrackInfoFromManifest(int retryCount) { - ExecutorService es = Executors.newSingleThreadExecutor(); final DataSource dataSource = this.mediaDataSourceFactory.createDataSource(); final Uri sourceUri = source.getUri(); final long startTime = source.getContentStartTime() * 1000 - 100; // s -> ms with 100ms offset - Future> result = es.submit(new Callable() { + Future> result = SHARED_EXECUTOR.submit(new Callable>() { final DataSource ds = dataSource; final Uri uri = sourceUri; final long startTimeUs = startTime * 1000; // ms -> us @@ -1687,7 +1685,6 @@ public class ReactExoplayerView extends FrameLayout implements if (results == null && retryCount < 1) { return this.getVideoTrackInfoFromManifest(++retryCount); } - es.shutdown(); return results; } catch (Exception e) { DebugLog.w(TAG, "error in getVideoTrackInfoFromManifest handling request:" + e.getMessage());