Added checks for PiP support

This commit is contained in:
ByteHamster 2018-04-09 00:04:02 +02:00
parent 0a5a31a169
commit 1831430a6e
2 changed files with 24 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
@ -225,7 +226,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
@Override @Override
protected void onPause() { protected void onPause() {
if (Build.VERSION.SDK_INT < 26 || !isInPictureInPictureMode()) { if (!supportsAndisInPictureInPictureMode()) {
if (controller != null) { if (controller != null) {
controller.reinitServiceIfPaused(); controller.reinitServiceIfPaused();
controller.pause(); 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() { private void checkFavorite() {
Playable playable = controller.getMedia(); Playable playable = controller.getMedia();
if (playable != null && playable instanceof FeedMedia) { if (playable != null && playable instanceof FeedMedia) {

View File

@ -101,14 +101,14 @@ public class VideoplayerActivity extends MediaplayerActivity {
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || !isInPictureInPictureMode()) { if (!supportsAndisInPictureInPictureMode()) {
videoControlsHider.stop(); videoControlsHider.stop();
} }
} }
@Override @Override
protected void onPause() { protected void onPause() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || !isInPictureInPictureMode()) { if (!supportsAndisInPictureInPictureMode()) {
if (controller != null && controller.getStatus() == PlayerStatus.PLAYING) { if (controller != null && controller.getStatus() == PlayerStatus.PLAYING) {
controller.pause(); controller.pause();
} }
@ -191,7 +191,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
private final View.OnTouchListener onVideoviewTouched = (v, event) -> { private final View.OnTouchListener onVideoviewTouched = (v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInPictureInPictureMode()) { if (supportsAndisInPictureInPictureMode()) {
return true; return true;
} }
videoControlsHider.stop(); videoControlsHider.stop();
@ -381,7 +381,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(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); menu.findItem(R.id.player_go_to_picture_in_picture).setVisible(true);
} }
return true; return true;
@ -390,7 +390,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.player_go_to_picture_in_picture) { 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(); getSupportActionBar().hide();
hideVideoControls(false); hideVideoControls(false);
enterPictureInPictureMode(); enterPictureInPictureMode();