fix picture in picture

This commit is contained in:
Page Asgardius 2022-10-09 20:24:03 -07:00
parent 19b20185f4
commit 7c7f05c760
2 changed files with 74 additions and 29 deletions

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/4.7_WXGA_API_24.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-10-10T02:57:43.359125Z" />
</component>
</project>

View file

@ -2,6 +2,7 @@ package asgardius.page.s3manager;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AppOpsManager;
import android.app.PictureInPictureParams;
import android.content.Context;
import android.content.pm.PackageManager;
@ -58,11 +59,13 @@ public class VideoPlayer extends AppCompatActivity {
MediaSessionCompat mediaSession;
MediaSessionConnector mediaSessionConnector;
StyledPlayerView.ControllerVisibilityListener control;
AppOpsManager appOpsManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
appOpsManager = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE);
mediaSession = new MediaSessionCompat(this, getPackageName());
mediaSessionConnector = new MediaSessionConnector(mediaSession);
hideSystemBars();
@ -216,10 +219,15 @@ public class VideoPlayer extends AppCompatActivity {
protected void enterPIPMode() {
try {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& this.getPackageManager()
.hasSystemFeature(
PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
PackageManager.FEATURE_PICTURE_IN_PICTURE) && appOpsManager.checkOpNoThrow(
AppOpsManager.OPSTR_PICTURE_IN_PICTURE,
this.getPackageManager().getApplicationInfo(this.getPackageName(),
PackageManager.GET_META_DATA).uid, this.getPackageName())
== AppOpsManager.MODE_ALLOWED) {
videoPosition = player.getCurrentPosition();
playerView.setUseController(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -229,6 +237,9 @@ public class VideoPlayer extends AppCompatActivity {
this.enterPictureInPictureMode();
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
@Override
@ -256,11 +267,16 @@ public class VideoPlayer extends AppCompatActivity {
super.onDestroy();
}
public void onStop() {
/*public void onStop() {
try {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& this.getPackageManager()
.hasSystemFeature(
PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
PackageManager.FEATURE_PICTURE_IN_PICTURE) && appOpsManager.checkOpNoThrow(
AppOpsManager.OPSTR_PICTURE_IN_PICTURE,
this.getPackageManager().getApplicationInfo(this.getPackageName(),
PackageManager.GET_META_DATA).uid, this.getPackageName())
== AppOpsManager.MODE_ALLOWED) {
mediaSessionConnector.setPlayer(null);
mediaSession.setActive(false);
player.release();
@ -268,8 +284,11 @@ public class VideoPlayer extends AppCompatActivity {
simpleCache.release();
finish();
}
super.onStop();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
super.onStop();
}*/
public void onResume(){
super.onResume();
@ -285,13 +304,22 @@ public class VideoPlayer extends AppCompatActivity {
}
public void onBackPressed() {
try {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& this.getPackageManager()
.hasSystemFeature(
PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
PackageManager.FEATURE_PICTURE_IN_PICTURE) && appOpsManager.checkOpNoThrow(
AppOpsManager.OPSTR_PICTURE_IN_PICTURE,
this.getPackageManager().getApplicationInfo(this.getPackageName(),
PackageManager.GET_META_DATA).uid, this.getPackageName())
== AppOpsManager.MODE_ALLOWED) {
enterPIPMode();
} else {
super.onBackPressed();
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
super.onBackPressed();
}
}
}