|
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; |
@@ -652,6 +654,28 @@ public void onPlayWhenReadyChanged(boolean isPlaying, int _ignored) { |
652 | 654 | } |
653 | 655 | } |
654 | 656 |
|
| 657 | + @RequiresApi(api = Build.VERSION_CODES.O) |
| 658 | + @Override |
| 659 | + public void onSurfaceSizeChanged(int width, int height) { |
| 660 | + Rect videoRect = new Rect(); |
| 661 | + mVideoView.getVideoSurfaceView().getGlobalVisibleRect(videoRect); |
| 662 | + |
| 663 | + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 664 | + videoRect.left += totalVerticalInset; |
| 665 | + videoRect.right += totalVerticalInset; |
| 666 | + } |
| 667 | + |
| 668 | + PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder() |
| 669 | + .setAspectRatio(new Rational(16, 9)) |
| 670 | + .setSourceRectHint(videoRect); |
| 671 | + |
| 672 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { |
| 673 | + builder.setAutoEnterEnabled(true); |
| 674 | + } |
| 675 | + |
| 676 | + mActivity.setPictureInPictureParams(builder.build()); |
| 677 | + } |
| 678 | + |
655 | 679 | /** |
656 | 680 | * Hides the preview image and updates the state |
657 | 681 | */ |
|
0 commit comments