2

I am trying to implement a picture-in-picture mode in my app similar to what we see when we click a youtube link in Whatsapp. Is it possible to create a similar view in our app.

Currently I'm letting Android to set my default screen size. This is the code segment :

final PictureInPictureParams.Builder pictureInPictureParamsBuilder =
                new PictureInPictureParams.Builder();
pictureInPictureParamsBuilder.build();
enterPictureInPictureMode(pictureInPictureParamsBuilder.build());

The above mentioned code allows my video to play in a small picture-in-picture window. I want to view the video in a bigger pip screen. I tried setting custom aspect ratios but none of them increase the size of the pip window.

How can I solve this?

Thanks in advance!!

1 Answers1

2

According to Google's sample project, the trick appears to be setting your desired width and height combination as a Rational for use with setAspectRatio.

final PictureInPictureParams.Builder pictureInPictureParamsBuilder =
                new PictureInPictureParams.Builder();
Rational aspectRatio = new Rational(width, height);
mPictureInPictureParamsBuilder.setAspectRatio(aspectRatio);
enterPictureInPictureMode(pictureInPictureParamsBuilder.build());

You should not need the second call to build. I saw the same results both with and without it.

Abandoned Cart
  • 4,512
  • 1
  • 34
  • 41
  • I tried doing this piece of code with the help of the Google's documentation, didn't work. – Prasanna Punekar Jun 04 '19 at 07:54
  • @PrasannaPunekar There must be an issue somewhere else in your code. I confirmed this worked with both "portrait" and "landscape" aspects before posting. – Abandoned Cart Jun 04 '19 at 13:14
  • @PrasannaPunekar: Did this work for you? I tried it out and this solution didn't work for me either :/ – Aayush Kumar Sep 16 '19 at 11:16
  • @AayushKumar You may want to try the sample project on its own and then work backwards to find where your issue lies, since the answer to your actual question can already be found in the comments. – Abandoned Cart Sep 17 '19 at 12:26