fix: fix the hardware back button

This commit is contained in:
wood1986 2022-08-18 01:12:08 -07:00
parent 810c62407f
commit 622f9d3f3f
2 changed files with 19 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton; import android.widget.ImageButton;
import androidx.activity.OnBackPressedCallback;
import com.google.android.exoplayer2.ui.PlayerControlView; import com.google.android.exoplayer2.ui.PlayerControlView;
public class FullScreenPlayerView extends Dialog { public class FullScreenPlayerView extends Dialog {
@ -13,15 +15,23 @@ public class FullScreenPlayerView extends Dialog {
private final ExoPlayerView exoPlayerView; private final ExoPlayerView exoPlayerView;
private ViewGroup parent; private ViewGroup parent;
private final FrameLayout containerView; 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); super(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
this.playerControlView = playerControlView; this.playerControlView = playerControlView;
this.exoPlayerView = exoPlayerView; this.exoPlayerView = exoPlayerView;
this.onBackPressedCallback = onBackPressedCallback;
containerView = new FrameLayout(context); containerView = new FrameLayout(context);
setContentView(containerView, generateDefaultLayoutParams()); setContentView(containerView, generateDefaultLayoutParams());
} }
@Override
public void onBackPressed() {
super.onBackPressed();
onBackPressedCallback.handleOnBackPressed();
}
@Override @Override
protected void onStart() { protected void onStart() {
parent = (FrameLayout)(exoPlayerView.getParent()); parent = (FrameLayout)(exoPlayerView.getParent());

View File

@ -17,6 +17,8 @@ import android.view.accessibility.CaptioningManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton; import android.widget.ImageButton;
import androidx.activity.OnBackPressedCallback;
import com.brentvatne.react.R; import com.brentvatne.react.R;
import com.brentvatne.receiver.AudioBecomingNoisyReceiver; import com.brentvatne.receiver.AudioBecomingNoisyReceiver;
import com.brentvatne.receiver.BecomingNoisyListener; import com.brentvatne.receiver.BecomingNoisyListener;
@ -669,7 +671,12 @@ class ReactExoplayerView extends FrameLayout implements
setControls(controls); setControls(controls);
applyModifiers(); applyModifiers();
startBufferCheckTimer(); 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 { private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException {