Picture In Picture
Learn how to enable users to activate Picture-in-Picture mode in your Android app. Available from version 1.1.7 Brid SDK.
Utilizing the Picture-in-Picture mode enables users to concurrently view videos while engaging with other applications.
To activate the Picture-in-Picture feature, select the corresponding option on the CMS portal. In the "LOOKS AND SKINS" section, under the player settings, check the Picture In Picture option as shown in the image.
Requirements
**Android: Nugat 7.0+ (API level 24+)
Picture-in-Picture mode will only work on devices with Android N or higher
It is currently not supported for Android TV
Implementation
This is the recommended implementation for Picture-in-Picture functionality. When the option is active, users can enter PiP mode either by clicking the button in the top right corner (look image) of the player or when the onUserLeaveHint() method is called by the Android system.
- Add the Picture in Picture support in the manifest file for the activity that hosts the BridPlayer.
<activity android:name=".MainActivity"
android:supportsPictureInPicture="true"
android:resizeableActivity="true">
</activity>
- Please note that to manually control multi-window configuration changes, such as resizing, you must add the android:configChanges attribute to the activity tag.
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
- Here is an example implementation extending the onUserLeaveHint() method, during which we invoke the method to enter Picture-in-Picture (PiP) mode
@Override
protected void onUserLeaveHint() {
super.onUserLeaveHint();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
bridPlayer.enterPictureInPictureMode();
}
}
override fun onUserLeaveHint() {
super.onUserLeaveHint()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
bridPlayer.enterPictureInPictureMode()
}
}
- To further extend the onPictureInPictureModeChanged method, you need to include the relevant logic associated with changes in the Picture-in-Picture (PiP) mode.
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
if (bridPlayer != null) {
bridPlayer.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
}
}
}
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
bridPlayer?.let {
it.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
}
}
}
Now that you have successfully implemented the Picture in Picture functionality, you can use the following sections to customize the implementation and listen for events.
This is the default behavior of the PiP mode. If you want to further modify the behavior, you can extend the basic Android lifecycle methods onPause(), onResume(), and onStop(). Additionally, you can always initiate the entry into PiP mode by calling the method bridPlayer.enterPictureInPictureMode().
If you want to interrupt playback and release resources when the PiP mode is dismissed by the user, it is necessary to extend the onStop() method.
@Override
protected void onStop() {
super.onStop();
if(isInPictureInPictureMode())
bridPlayer.release();
}
Events
You have access to two events related to the PiP mode. One signals when entering PiP mode, and the other signals when exiting the mode. To learn how to use the events of the bridPlayer, refer to the 'Event listeners' section.
public static final String EVENT_ENTER_PICTURE_IN_PICTURE = "enpip";
public static final String EVENT_EXIT_PICTURE_IN_PICTURE = "expip";
Updated 10 months ago