Вот как я реализовал PictureInPicture
в своем приложении.
@Override
protected void onUserLeaveHint() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (!isInPictureInPictureMode()) {
Rational rational = new Rational(250, 150); //you can use VideoView getWidth(),getHeight() here
builder.setAspectRatio(rational).build();
enterPictureInPictureMode(builder.build());
}
}
}
Затем определите, свернул ли пользователь экран
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
if (isInPictureInPictureMode) {
Toast.makeText(this, "in picture in picture mode.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "out of picture in picture mode.", Toast.LENGTH_SHORT).show();
}
}
Инициализировать PictureInPitureParam.Builder
в onCreate ()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder = new PictureInPictureParams.Builder();
}