From 622f9d3f3f2d5bb2bb5568eee740f2972685f255 Mon Sep 17 00:00:00 2001 From: wood1986 <5212215+wood1986@users.noreply.github.com> Date: Thu, 18 Aug 2022 01:12:08 -0700 Subject: [PATCH] fix: fix the hardware back button --- .../brentvatne/exoplayer/FullScreenPlayerView.java | 12 +++++++++++- .../com/brentvatne/exoplayer/ReactExoplayerView.java | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/FullScreenPlayerView.java b/android/src/main/java/com/brentvatne/exoplayer/FullScreenPlayerView.java index 4a7edb1d..f57bb964 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/FullScreenPlayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/FullScreenPlayerView.java @@ -6,6 +6,8 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageButton; +import androidx.activity.OnBackPressedCallback; + import com.google.android.exoplayer2.ui.PlayerControlView; public class FullScreenPlayerView extends Dialog { @@ -13,15 +15,23 @@ public class FullScreenPlayerView extends Dialog { private final ExoPlayerView exoPlayerView; private ViewGroup parent; private final FrameLayout containerView; + private final OnBackPressedCallback onBackPressedCallback; - public FullScreenPlayerView(Context context, ExoPlayerView exoPlayerView, PlayerControlView playerControlView) { + public FullScreenPlayerView(Context context, ExoPlayerView exoPlayerView, PlayerControlView playerControlView, OnBackPressedCallback onBackPressedCallback) { super(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen); this.playerControlView = playerControlView; this.exoPlayerView = exoPlayerView; + this.onBackPressedCallback = onBackPressedCallback; containerView = new FrameLayout(context); setContentView(containerView, generateDefaultLayoutParams()); } + @Override + public void onBackPressed() { + super.onBackPressed(); + onBackPressedCallback.handleOnBackPressed(); + } + @Override protected void onStart() { parent = (FrameLayout)(exoPlayerView.getParent()); diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index c80d86f5..511437da 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -17,6 +17,8 @@ import android.view.accessibility.CaptioningManager; import android.widget.FrameLayout; import android.widget.ImageButton; +import androidx.activity.OnBackPressedCallback; + import com.brentvatne.react.R; import com.brentvatne.receiver.AudioBecomingNoisyReceiver; import com.brentvatne.receiver.BecomingNoisyListener; @@ -669,7 +671,12 @@ class ReactExoplayerView extends FrameLayout implements setControls(controls); applyModifiers(); startBufferCheckTimer(); - fullScreenPlayerView = new FullScreenPlayerView(getContext(), exoPlayerView, playerControlView); + fullScreenPlayerView = new FullScreenPlayerView(getContext(), exoPlayerView, playerControlView, new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + setFullscreen(false); + } + }); } private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException {