Added checks for PiP support
This commit is contained in:
parent
0a5a31a169
commit
1831430a6e
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue