Add focusable prop

This commit is contained in:
Liam Potter
2022-09-26 01:51:18 +01:00
parent 9501d43357
commit 1406b9ad08
5 changed files with 29 additions and 4 deletions

View File

@@ -190,6 +190,7 @@ class ReactExoplayerView extends FrameLayout implements
private Dynamic textTrackValue;
private ReadableArray textTracks;
private boolean disableFocus;
private boolean focusable = true;
private boolean disableBuffering;
private long contentStartTime = -1L;
private boolean disableDisconnectError;
@@ -284,6 +285,8 @@ class ReactExoplayerView extends FrameLayout implements
addView(exoPlayerView, 0, layoutParams);
exoPlayerView.setFocusable(this.focusable);
mainHandler = new Handler();
}
@@ -571,7 +574,7 @@ class ReactExoplayerView extends FrameLayout implements
}
}
}, 1);
}
private void initializePlayerCore(ReactExoplayerView self) {
@@ -1119,7 +1122,7 @@ class ReactExoplayerView extends FrameLayout implements
WritableArray videoTracks = Arguments.createArray();
MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo();
if (info == null || trackRendererIndex == C.INDEX_UNSET) {
return videoTracks;
}
@@ -1578,7 +1581,7 @@ class ReactExoplayerView extends FrameLayout implements
for (int j = 0; j < group.length; j++) {
allTracks.add(j);
}
// Valiate list of all tracks and add only supported formats
int supportedFormatLength = 0;
ArrayList<Integer> supportedTrackList = new ArrayList<Integer>();
@@ -1737,13 +1740,18 @@ class ReactExoplayerView extends FrameLayout implements
this.disableFocus = disableFocus;
}
public void setFocusable(boolean focusable) {
this.focusable = focusable;
exoPlayerView.setFocusable(this.focusable);
}
public void setBackBufferDurationMs(int backBufferDurationMs) {
Runtime runtime = Runtime.getRuntime();
long usedMemory = runtime.totalMemory() - runtime.freeMemory();
long freeMemory = runtime.maxMemory() - usedMemory;
long reserveMemory = (long)minBackBufferMemoryReservePercent * runtime.maxMemory();
if (reserveMemory > freeMemory) {
// We don't have enough memory in reserve so we will
// We don't have enough memory in reserve so we will
Log.w("ExoPlayer Warning", "Not enough reserve memory, setting back buffer to 0ms to reduce memory pressure!");
this.backBufferDurationMs = 0;
return;

View File

@@ -70,6 +70,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
private static final String PROP_DISABLE_FOCUS = "disableFocus";
private static final String PROP_DISABLE_BUFFERING = "disableBuffering";
private static final String PROP_DISABLE_DISCONNECT_ERROR = "disableDisconnectError";
private static final String PROP_FOCUSABLE = "focusable";
private static final String PROP_FULLSCREEN = "fullscreen";
private static final String PROP_USE_TEXTURE_VIEW = "useTextureView";
private static final String PROP_SECURE_VIEW = "useSecureView";
@@ -304,6 +305,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
videoView.setDisableFocus(disableFocus);
}
@ReactProp(name = PROP_FOCUSABLE, defaultBoolean = true)
public void setFocusable(final ReactExoplayerView videoView, final boolean focusable) {
videoView.setFocusable(focusable);
}
@ReactProp(name = PROP_BACK_BUFFER_DURATION_MS, defaultInt = 0)
public void setBackBufferDurationMs(final ReactExoplayerView videoView, final int backBufferDurationMs) {
videoView.setBackBufferDurationMs(backBufferDurationMs);