From 7cd164ea2c9e9bdca38f6d32b053f0272ed10211 Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Mon, 2 Jan 2023 21:52:08 +0100 Subject: [PATCH] chore(android): small refactor to avoid unnecessary allocations --- .../exoplayer/ReactExoplayerView.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 05f612cd..93c39187 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -1531,6 +1531,14 @@ class ReactExoplayerView extends FrameLayout implements this.preventsDisplaySleepDuringVideoPlayback = preventsDisplaySleepDuringVideoPlayback; } + public void disableTrack(int rendererIndex) { + DefaultTrackSelector.Parameters disableParameters = trackSelector.getParameters() + .buildUpon() + .setRendererDisabled(rendererIndex, true) + .build(); + trackSelector.setParameters(disableParameters); + } + public void setSelectedTrack(int trackType, String type, Dynamic value) { if (player == null) return; int rendererIndex = getTrackRendererIndex(trackType); @@ -1551,13 +1559,8 @@ class ReactExoplayerView extends FrameLayout implements type = "default"; } - DefaultTrackSelector.Parameters disableParameters = trackSelector.getParameters() - .buildUpon() - .setRendererDisabled(rendererIndex, true) - .build(); - if (type.equals("disabled")) { - trackSelector.setParameters(disableParameters); + disableTrack(rendererIndex); return; } else if (type.equals("language")) { for (int i = 0; i < groups.length; ++i) { @@ -1675,7 +1678,7 @@ class ReactExoplayerView extends FrameLayout implements } if (groupIndex == C.INDEX_UNSET) { - trackSelector.setParameters(disableParameters); + disableTrack(rendererIndex); return; }