chore(android): small refactor to avoid unnecessary allocations

This commit is contained in:
olivier bouillet 2023-01-02 21:52:08 +01:00
parent b3fffcfb59
commit 7cd164ea2c

View File

@ -1531,6 +1531,14 @@ class ReactExoplayerView extends FrameLayout implements
this.preventsDisplaySleepDuringVideoPlayback = preventsDisplaySleepDuringVideoPlayback; 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) { public void setSelectedTrack(int trackType, String type, Dynamic value) {
if (player == null) return; if (player == null) return;
int rendererIndex = getTrackRendererIndex(trackType); int rendererIndex = getTrackRendererIndex(trackType);
@ -1551,13 +1559,8 @@ class ReactExoplayerView extends FrameLayout implements
type = "default"; type = "default";
} }
DefaultTrackSelector.Parameters disableParameters = trackSelector.getParameters()
.buildUpon()
.setRendererDisabled(rendererIndex, true)
.build();
if (type.equals("disabled")) { if (type.equals("disabled")) {
trackSelector.setParameters(disableParameters); disableTrack(rendererIndex);
return; return;
} else if (type.equals("language")) { } else if (type.equals("language")) {
for (int i = 0; i < groups.length; ++i) { for (int i = 0; i < groups.length; ++i) {
@ -1675,7 +1678,7 @@ class ReactExoplayerView extends FrameLayout implements
} }
if (groupIndex == C.INDEX_UNSET) { if (groupIndex == C.INDEX_UNSET) {
trackSelector.setParameters(disableParameters); disableTrack(rendererIndex);
return; return;
} }