From 28fb03321ea3ea87261f9a954ed7972154f41744 Mon Sep 17 00:00:00 2001 From: 12aw Date: Thu, 1 Sep 2022 21:22:23 +0200 Subject: [PATCH] fix crash on PIP (Christian Schneppe) --- .../conversations/ui/MediaViewerActivity.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/MediaViewerActivity.java b/src/main/java/eu/siacs/conversations/ui/MediaViewerActivity.java index 7ec2ed3f5..897fe3193 100644 --- a/src/main/java/eu/siacs/conversations/ui/MediaViewerActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/MediaViewerActivity.java @@ -378,15 +378,17 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On try { binding.messageVideoView.hideController(); binding.speedDial.setVisibility(View.GONE); - if (Compatibility.runsTwentySix()) { - final Rational rational = new Rational(width, height); - final Rational clippedRational = Rationals.clip(rational); - final PictureInPictureParams params = new PictureInPictureParams.Builder() - .setAspectRatio(clippedRational) - .build(); - this.enterPictureInPictureMode(params); - } else { - this.enterPictureInPictureMode(); + if (supportsPIP()) { + if (Compatibility.runsTwentySix()) { + final Rational rational = new Rational(width, height); + final Rational clippedRational = Rationals.clip(rational); + final PictureInPictureParams params = new PictureInPictureParams.Builder() + .setAspectRatio(clippedRational) + .build(); + this.enterPictureInPictureMode(params); + } else { + this.enterPictureInPictureMode(); + } } } catch (final IllegalStateException e) { // this sometimes happens on Samsung phones (possibly when Knox is enabled) @@ -422,7 +424,7 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On @Override public void onBackPressed() { - if (isVideo && isPlaying() && Compatibility.runsTwentyFour() && getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { + if (isVideo && isPlaying() && supportsPIP()) { PIPVideo(); } else { super.onBackPressed(); @@ -484,7 +486,7 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On private void stopPlayer() { if (player != null && isVideo) { - if ((Compatibility.runsTwentyFour()) && getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { + if (supportsPIP()) { finishAndRemoveTask(); } if (isPlaying()) { @@ -595,4 +597,12 @@ public class MediaViewerActivity extends XmppActivity implements AudioManager.On private void hideFAB() { binding.speedDial.hide(); } + + private boolean supportsPIP() { + if (Compatibility.runsTwentyFour()) { + return this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE); + } else { + return false; + } + } } \ No newline at end of file