diff --git a/API.md b/API.md index def2b025..cb781e2c 100644 --- a/API.md +++ b/API.md @@ -277,6 +277,7 @@ var styles = StyleSheet.create({ |[disableDisconnectError](#disableDisconnectError)|Android| |[filter](#filter)|iOS| |[filterEnabled](#filterEnabled)|iOS| +|[focusable](#focusable)|Android| |[fullscreen](#fullscreen)|iOS| |[fullscreenAutorotate](#fullscreenautorotate)|iOS| |[fullscreenOrientation](#fullscreenorientation)|iOS| @@ -486,6 +487,14 @@ Enable video filter. Platforms: iOS +#### Focusable +Whether this video view should be focusable with a non-touch input device, eg. receive focus with a hardware keyboard. +* **false** - Makes view unfocusable +* **true (default)** - Makes view focusable + +Platforms: Android + + #### fullscreen Controls whether the player enters fullscreen on play. * **false (default)** - Don't display the video in fullscreen diff --git a/CHANGELOG.md b/CHANGELOG.md index f2734ed0..3f207b56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Changelog ### Version 6.0.0-alpha4 - Android: Switch Google's maven repository to default `google()` [#2860](https://github.com/react-native-video/react-native-video/pull/2860) +- Android: Implement focusable prop so the video view can toggle whether it is focusable for non-touch devices [#2819](https://github.com/react-native-video/react-native-video/issues/2819) ### Version 6.0.0-alpha3 - fix ios build [#2854](https://gthub.com/react-native-video/react-native-video/pull/2854) diff --git a/Video.js b/Video.js index 287573a1..71fa94a3 100644 --- a/Video.js +++ b/Video.js @@ -483,6 +483,7 @@ Video.propTypes = { reportBandwidth: PropTypes.bool, contentStartTime: PropTypes.number, disableFocus: PropTypes.bool, + focusable: PropTypes.bool, disableBuffering: PropTypes.bool, controls: PropTypes.bool, audioOnly: PropTypes.bool, diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 2f663197..6d94dc6c 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -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 supportedTrackList = new ArrayList(); @@ -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; diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index ce1d6a8c..d9297a71 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -70,6 +70,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager