From 2af360a7bb0462582a05f20c9f5f7fdf508b0ade Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 14 Feb 2022 21:17:22 -0400 Subject: [PATCH] add useSecureView prop to prevent screen recording --- README.md | 13 +++++++++++++ Video.js | 1 + .../brentvatne/exoplayer/ExoPlayerView.java | 18 +++++++++++++++++- .../exoplayer/ReactExoplayerView.java | 4 ++++ .../exoplayer/ReactExoplayerViewManager.java | 6 ++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c0a34da6..2881926f 100644 --- a/README.md +++ b/README.md @@ -316,6 +316,7 @@ var styles = StyleSheet.create({ * [textTracks](#texttracks) * [trackId](#trackId) * [useTextureView](#usetextureview) +* [useSecureView](#useSecureView) * [volume](#volume) * [localSourceEncryptionKeyScheme](#localSourceEncryptionKeyScheme) @@ -911,6 +912,18 @@ useTextureView can only be set at same time you're setting the source. Platforms: Android ExoPlayer +#### useSecureView +Force the output to a SurfaceView and enables the secure surface. + +This will override useTextureView flag. + +SurfaceView is is the only one that can be labeled as secure. + +* **true** - Use security +* **false (default)** - Do not use security + +Platforms: Android ExoPlayer + #### volume Adjust the volume. * **1.0 (default)** - Play at full volume diff --git a/Video.js b/Video.js index 0a97be1d..db88752f 100644 --- a/Video.js +++ b/Video.js @@ -488,6 +488,7 @@ Video.propTypes = { fullscreenOrientation: PropTypes.oneOf(['all', 'landscape', 'portrait']), progressUpdateInterval: PropTypes.number, useTextureView: PropTypes.bool, + useSecureView: PropTypes.bool, hideShutterView: PropTypes.bool, onLoadStart: PropTypes.func, onLoad: PropTypes.func, diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java index 61cb0dd6..a91618d5 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java @@ -41,6 +41,7 @@ public final class ExoPlayerView extends FrameLayout { private ViewGroup.LayoutParams layoutParams; private boolean useTextureView = true; + private boolean useSecureView = false; private boolean hideShutterView = false; public ExoPlayerView(Context context) { @@ -103,7 +104,15 @@ public final class ExoPlayerView extends FrameLayout { } private void updateSurfaceView() { - View view = useTextureView ? new TextureView(context) : new SurfaceView(context); + View view; + if (!useTextureView || useSecureView) { + view = new SurfaceView(context); + if (useSecureView) { + ((SurfaceView)view).setSecure(true); + } + } else { + view = new TextureView(context); + } view.setLayoutParams(layoutParams); surfaceView = view; @@ -178,6 +187,13 @@ public final class ExoPlayerView extends FrameLayout { } } + public void useSecureView(boolean useSecureView) { + if (useSecureView != this.useSecureView) { + this.useSecureView = useSecureView; + updateSurfaceView(); + } + } + public void setHideShutterView(boolean hideShutterView) { this.hideShutterView = hideShutterView; updateShutterViewVisibility(); diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 5dcb5e0d..e4000116 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -1696,6 +1696,10 @@ class ReactExoplayerView extends FrameLayout implements exoPlayerView.setUseTextureView(finallyUseTextureView); } + public void useSecureView(boolean useSecureView) { + exoPlayerView.useSecureView(useSecureView); + } + public void setHideShutterView(boolean hideShutterView) { exoPlayerView.setHideShutterView(hideShutterView); } diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 5d8a84d4..3744fcae 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -72,6 +72,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager