Setting up Picture-in-Picture with the Player Android SDK

In this tutorial, we will guide you through 3 steps necessary to implement a basic Picture-in-Picture implementation with the Bitmovin Player Android SDK

Prerequisites

Note: PiP is available only on Android 8.0 (API level 26) and above.

Step 1: Enable PiP support for the Activity

By default, the system does not automatically support PiP for apps. If you want support PiP in your app, register your video activity in your manifest by setting android:supportsPictureInPicture to true. Also, specify that your activity handles layout configuration changes so that your activity doesn't relaunch when layout changes occur during PiP mode transitions.

<activity android:name="VideoActivity"
    android:supportsPictureInPicture="true"
    android:configChanges=
        "screenSize|smallestScreenSize|screenLayout|orientation"
    ...

Step 2: Providing a PictureInPictureHandler

Create a PiP handler and pass it to the PlayerView, this will enable the default UI to show PiP button, which the user can press to enter PiP mode. For default handling you can use the provided DefaultPictureInPictureHandler which handles entering and exiting PiP mode automatically and resizes the PiP window to match video's aspect ratio.

Note: For more advanced use cases the PictureInPictureHandler interface can be implemented and passed to the PlayerView

val pictureInPictureHandler = DefaultPictureInPictureHandler(activity, player)
playerView.setPictureInPictureHandler(pictureInPictureHandler)

Step 3: Update the UI

Make necessary changes to your app's UI. Since PiP mode on Android is just a whole Activity displayed in a small floating window this usually means hiding all the UI elements except for the PlayerView. This can be done by overriding your Activity's onPictureInPictureModeChanged().

It's important to also let the PlayerView know that the PiP mode has changed. This is done by calling playerView.onPictureInPictureModeChanged().

override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
    super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
    // Make the appropriate UI changes, for example hiding and showing the action bar.
    if (isInPictureInPictureMode) {
        supportActionBar?.hide()
    } else {
        supportActionBar?.show()
    }
    playerView.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
}

Supported Picture-in-Picture events

The supported Picture-in-Picture events on PlayerView are:

For more information refer to PlayerView, PictureInPictureHandler and PlayerEvent .