Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(PictureInPictureModule): catch the RuntimeException

paweldomas9cbcbf6e26d3
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java
index ff3d0c5333..bf15edcc6c 100644
--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/PictureInPictureModule.java
@@ -44,14 +44,26 @@ public class PictureInPictureModule extends ReactContextBaseJavaModule {
PictureInPictureParams.Builder builder
= new PictureInPictureParams.Builder()
.setAspectRatio(new Rational(1, 1));
- boolean r
- = currentActivity.enterPictureInPictureMode(builder.build());
+ Throwable error;
- if (r) {
+ // https://developer.android.com/reference/android/app/Activity.html#enterPictureInPictureMode(android.app.PictureInPictureParams)
+ //
+ // The system may disallow entering picture-in-picture in various
+ // cases, including when the activity is not visible, if the screen
+ // is locked or if the user has an activity pinned.
+ try {
+ error
+ = currentActivity.enterPictureInPictureMode(builder.build())
+ ? null
+ : new Exception("Failed to enter Picture-in-Picture");
+ } catch (RuntimeException re) {
+ error = re;
+ }
+
+ if (error == null) {
promise.resolve(null);
} else {
- promise.reject(
- new Exception("Failed to enter Picture-in-Picture"));
+ promise.reject(error);
}
return;
diff --git a/react/features/mobile/picture-in-picture/actions.js b/react/features/mobile/picture-in-picture/actions.js
index 3102581f95..0a271a2cf5 100644
--- a/react/features/mobile/picture-in-picture/actions.js
+++ b/react/features/mobile/picture-in-picture/actions.js
@@ -23,6 +23,10 @@ export function enterPictureInPicture() {
return (dispatch: Dispatch, getState: Function) => {
const state = getState();
const { app } = state['features/app'];
+
+ // FIXME We want to be able to enter Picture-in-Picture as soon as we
+ // are on the Conference page i.e. even before `joining` was set in the
+ // reducer.
const { conference, joining } = state['features/base/conference'];
if (app