2

I need to play youtube video inside my application in picture in picture mode without resizing my original activity just want to display youtube in full screen or picture in picture mode, similar kind of feature like whatsapp play youtube video.

I am trying playing video using exoplayer is this good way to achieve picture in picture functionality.

I have tried to find some sample code, tutorial but unable to get it. if you have any link for related topic is most welcome.

dev_swat
  • 1,264
  • 1
  • 12
  • 26

1 Answers1

1

Just use this code to start Picture-In-Picture mode

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            Rational rational = new Rational(250, 150);
            PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder();
            builder.setAspectRatio(rational).build();
            enterPictureInPictureMode(builder.build());
        }
    }

Also add this lines to Your activity's tag in Manifest file

android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
        android:launchMode="singleTask"
        android:resizeableActivity="true"
        android:supportsPictureInPicture="true"
        tools:targetApi="n"

you can also refer to this link if it can help - https://stackoverflow.com/a/12439378/10752962

Happy Coding @dev_swat

Vivek Thummar
  • 395
  • 4
  • 17