fix picture in picture
This commit is contained in:
parent
19b20185f4
commit
7c7f05c760
2 changed files with 74 additions and 29 deletions
17
.idea/deploymentTargetDropDown.xml
Normal file
17
.idea/deploymentTargetDropDown.xml
Normal 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>
|
|
@ -2,6 +2,7 @@ package asgardius.page.s3manager;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.app.AppOpsManager;
|
||||||
import android.app.PictureInPictureParams;
|
import android.app.PictureInPictureParams;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
@ -58,11 +59,13 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
MediaSessionCompat mediaSession;
|
MediaSessionCompat mediaSession;
|
||||||
MediaSessionConnector mediaSessionConnector;
|
MediaSessionConnector mediaSessionConnector;
|
||||||
StyledPlayerView.ControllerVisibilityListener control;
|
StyledPlayerView.ControllerVisibilityListener control;
|
||||||
|
AppOpsManager appOpsManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_video_player);
|
setContentView(R.layout.activity_video_player);
|
||||||
|
appOpsManager = (AppOpsManager)getSystemService(Context.APP_OPS_SERVICE);
|
||||||
mediaSession = new MediaSessionCompat(this, getPackageName());
|
mediaSession = new MediaSessionCompat(this, getPackageName());
|
||||||
mediaSessionConnector = new MediaSessionConnector(mediaSession);
|
mediaSessionConnector = new MediaSessionConnector(mediaSession);
|
||||||
hideSystemBars();
|
hideSystemBars();
|
||||||
|
@ -216,10 +219,15 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
protected void enterPIPMode() {
|
protected void enterPIPMode() {
|
||||||
|
try {
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
||||||
&& this.getPackageManager()
|
&& this.getPackageManager()
|
||||||
.hasSystemFeature(
|
.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();
|
videoPosition = player.getCurrentPosition();
|
||||||
playerView.setUseController(false);
|
playerView.setUseController(false);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
@ -229,6 +237,9 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
this.enterPictureInPictureMode();
|
this.enterPictureInPictureMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -256,11 +267,16 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStop() {
|
/*public void onStop() {
|
||||||
|
try {
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
||||||
&& this.getPackageManager()
|
&& this.getPackageManager()
|
||||||
.hasSystemFeature(
|
.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);
|
mediaSessionConnector.setPlayer(null);
|
||||||
mediaSession.setActive(false);
|
mediaSession.setActive(false);
|
||||||
player.release();
|
player.release();
|
||||||
|
@ -268,8 +284,11 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
simpleCache.release();
|
simpleCache.release();
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
super.onStop();
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
super.onStop();
|
||||||
|
}*/
|
||||||
|
|
||||||
public void onResume(){
|
public void onResume(){
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -285,13 +304,22 @@ public class VideoPlayer extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
try {
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
||||||
&& this.getPackageManager()
|
&& this.getPackageManager()
|
||||||
.hasSystemFeature(
|
.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();
|
enterPIPMode();
|
||||||
} else {
|
} else {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue