From 039125332c2e8984dd3c0a24840f17ee79bb0be3 Mon Sep 17 00:00:00 2001 From: Joe Milham Date: Tue, 15 Oct 2024 14:46:17 -0300 Subject: [PATCH] Safely re-add view after fullscreen. Ensure non-fullscreen after PiP --- .../com/jwplayer/rnjwplayer/RNJWPlayerView.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerView.java b/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerView.java index 8e79859..ea310da 100755 --- a/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerView.java +++ b/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerView.java @@ -18,12 +18,10 @@ import android.os.Handler; import android.os.Looper; import android.util.Log; -import android.view.Choreographer; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.RelativeLayout; @@ -41,8 +39,8 @@ import com.facebook.react.uimanager.events.RCTEventEmitter; import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; -import com.jwplayer.pub.api.JsonHelper; import com.jwplayer.pub.api.JWPlayer; +import com.jwplayer.pub.api.JsonHelper; import com.jwplayer.pub.api.UiGroup; import com.jwplayer.pub.api.background.MediaServiceController; import com.jwplayer.pub.api.configuration.PlayerConfig; @@ -113,6 +111,8 @@ import com.jwplayer.pub.api.media.playlists.PlaylistItem; import com.jwplayer.ui.views.CueMarkerSeekbar; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -120,8 +120,6 @@ import java.util.Map; import java.util.Objects; -import org.json.JSONObject; - public class RNJWPlayerView extends RelativeLayout implements VideoPlayerEvents.OnFullscreenListener, VideoPlayerEvents.OnReadyListener, @@ -622,6 +620,9 @@ public void onFullscreenExitRequested() { mPlayerViewContainer.post(new Runnable() { @Override public void run() { + // View may not have been removed properly (especially if returning from PiP) + mPlayerViewContainer.removeView(mPlayerView); + mPlayerViewContainer.addView(mPlayerView, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); @@ -714,6 +715,11 @@ public void onReceive(Context context, Intent intent) { mPlayer.setForceControlsVisibility(true); mPlayer.setForceControlsVisibility(false); + // If player was in fullscreen when going into PiP, we need to force it back out + if (mPlayer.getFullscreen()) { + mPlayer.setFullscreen(false, true); + } + // Strip player view rootView.removeView(mPlayerView);