From 1831430a6e47be1e34d2e8a4b977e79289ca7b2b Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Mon, 9 Apr 2018 00:04:02 +0200 Subject: Added checks for PiP support --- .../antennapod/activity/MediaplayerActivity.java | 20 +++++++++++++++++++- .../antennapod/activity/VideoplayerActivity.java | 10 +++++----- 2 files changed, 24 insertions(+), 6 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index f3c0760f3..b51f45d93 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -4,6 +4,7 @@ import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.PixelFormat; @@ -225,7 +226,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements @Override protected void onPause() { - if (Build.VERSION.SDK_INT < 26 || !isInPictureInPictureMode()) { + if (!supportsAndisInPictureInPictureMode()) { if (controller != null) { controller.reinitServiceIfPaused(); controller.pause(); @@ -907,6 +908,23 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements } } + /* package */ boolean supportsPictureInPicture() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + PackageManager packageManager = getApplicationContext().getPackageManager(); + return packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE); + } else { + return false; + } + } + + /* package */ boolean supportsAndisInPictureInPictureMode() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && supportsPictureInPicture()) { + return isInPictureInPictureMode(); + } else { + return false; + } + } + private void checkFavorite() { Playable playable = controller.getMedia(); if (playable != null && playable instanceof FeedMedia) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java index e23291e0d..4ab934cc2 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -101,14 +101,14 @@ public class VideoplayerActivity extends MediaplayerActivity { @Override protected void onStop() { super.onStop(); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || !isInPictureInPictureMode()) { + if (!supportsAndisInPictureInPictureMode()) { videoControlsHider.stop(); } } @Override protected void onPause() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || !isInPictureInPictureMode()) { + if (!supportsAndisInPictureInPictureMode()) { if (controller != null && controller.getStatus() == PlayerStatus.PLAYING) { controller.pause(); } @@ -191,7 +191,7 @@ public class VideoplayerActivity extends MediaplayerActivity { private final View.OnTouchListener onVideoviewTouched = (v, event) -> { if (event.getAction() == MotionEvent.ACTION_DOWN) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInPictureInPictureMode()) { + if (supportsAndisInPictureInPictureMode()) { return true; } videoControlsHider.stop(); @@ -381,7 +381,7 @@ public class VideoplayerActivity extends MediaplayerActivity { @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + if (supportsPictureInPicture()) { menu.findItem(R.id.player_go_to_picture_in_picture).setVisible(true); } return true; @@ -390,7 +390,7 @@ public class VideoplayerActivity extends MediaplayerActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.player_go_to_picture_in_picture) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + if (supportsPictureInPicture() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { getSupportActionBar().hide(); hideVideoControls(false); enterPictureInPictureMode(); -- cgit v1.2.3