|
2 | 2 |
|
3 | 3 | import android.app.Activity;
|
4 | 4 | import android.app.PendingIntent;
|
| 5 | +import android.app.PictureInPictureParams; |
5 | 6 | import android.content.BroadcastReceiver;
|
6 | 7 | import android.content.ComponentName;
|
7 | 8 | import android.content.Context;
|
|
22 | 23 | import android.transition.Transition;
|
23 | 24 | import android.util.DisplayMetrics;
|
24 | 25 | import android.util.Log;
|
| 26 | +import android.util.Rational; |
25 | 27 | import android.view.Display;
|
26 | 28 | import android.view.DisplayCutout;
|
27 | 29 | import android.view.LayoutInflater;
|
@@ -653,6 +655,28 @@ public void onPlayWhenReadyChanged(boolean isPlaying, int _ignored) {
|
653 | 655 | }
|
654 | 656 | }
|
655 | 657 |
|
| 658 | + @RequiresApi(api = Build.VERSION_CODES.O) |
| 659 | + @Override |
| 660 | + public void onSurfaceSizeChanged(int width, int height) { |
| 661 | + Rect videoRect = new Rect(); |
| 662 | + mVideoView.getVideoSurfaceView().getGlobalVisibleRect(videoRect); |
| 663 | + |
| 664 | + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 665 | + videoRect.left += totalVerticalInset; |
| 666 | + videoRect.right += totalVerticalInset; |
| 667 | + } |
| 668 | + |
| 669 | + PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder() |
| 670 | + .setAspectRatio(new Rational(16, 9)) |
| 671 | + .setSourceRectHint(videoRect); |
| 672 | + |
| 673 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { |
| 674 | + builder.setAutoEnterEnabled(true); |
| 675 | + } |
| 676 | + |
| 677 | + mActivity.setPictureInPictureParams(builder.build()); |
| 678 | + } |
| 679 | + |
656 | 680 | /**
|
657 | 681 | * Hides the preview image and updates the state
|
658 | 682 | */
|
|
0 commit comments