I have an app which plays video from youtube and i have coded the link in my MainActivity class..
I have made the video played in my app as expected..
I have t
I solved my problem using PictureInPictureParams
as follows
First i created a Button
(enter_pip) in my xml and in the OnClick
i coded the following :
enter_pip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (android.os.Build.VERSION.SDK_INT >= 26) {
//Trigger PiP mode
try {
Rational rational = new Rational(youTubeView.getWidth(), youTubeView.getHeight());
PictureInPictureParams mParams =
new PictureInPictureParams.Builder()
.setAspectRatio(rational)
.build();
enterPictureInPictureMode(mParams);
} catch (IllegalStateException e) {
e.printStackTrace();
}
} else {
Toast.makeText(MainActivity.this, "API 26 needed to perform PiP", Toast.LENGTH_SHORT).show();
}
}
});
I also added the following attributes in my AndroidManifest to my PipActivity to support Picture in Picture in my Activity
<activity
android:name=".PipActivity"
android:launchMode="singleTask"
android:supportsPictureInPicture="true"
android:theme="@style/AppTheme.NoActionBar" />