Picture-in-picture
With v2.0 of the Android SDK, we now support Picture-in-Picture (PiP) mode. This feature allows you to watch videos in a floating window on top of your other windows. Users can keep an eye on the video playback while interacting with other sites or applications. PiP mode offers several benefits to enhance the user experience:
- Users can take advantage of a dynamic multitasking environment . This minimizes the effects of context switching and improves the user experience, allowing viewers to continue watching a video while doing other tasks.
- Viewers experience consistent playback when switching between screen modes . With Wowza Flowplayer's PiP handler, the transition between full-screen and PiP mode occurs seamlessly without playback interruptions.
For a demonstration of PiP mode, see our FlowplayerSupportFragmentPiPActivity demo.
Before you start
The device must be running at least Android Oreo (API level 26) for Picture-in-Picture mode to work with Wowza Flowplayer.
Enable PiP mode
To enable PiP mode while using the player in your Android application, you need to update your AndroidManifest.xml file. For this configuration to work, set the android:supportsPictureInPicture
attribute to true
in your <activity>
tag:
<activity android:name=".YourActivityName"
android:supportsPictureInPicture="true">
</activity>
Enter PiP mode
You may want to enter PiP mode when the user takes a particular action within your Android application. For example, when a user event triggers the onUserLeaveHint()
callback and the user presses the home button. In this instance, use the following code to enter PiP mode:
// Called when the user decides to send the activity to the background
override fun onUserLeaveHint() {
super.onUserLeaveHint()
// Check if device's SDK version is at least Android Oreo (API level 26) and supports PiP
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val params = PictureInPictureParams.Builder().build()
// Enter PiP mode with specified parameters
enterPictureInPictureMode(params)
// If device doesn't support PiP, display message or do nothing
} else {
Toast.makeText(this, "PiP is supported only for API 26 and above", Toast.LENGTH_LONG)
.show()
}
}
Handle PiP mode changes
If you're using the FlowplayerSupportFragment
class to manage your player instance, no additional steps are needed to detect PiP mode changes. The player's lifecycle is handled automatically.
However, if you're using the FlowplayerView
class to manage your player, you need to manually invoke the onPictureInPictureModeChanged() method to handle PiP mode changes. This method takes the isInPictureInPictureMode
parameter to determine if the host activity is in PiP mode.
You can override the onPictureInPictureModeChanged()
callback in your activity of fragment, and then invoke the player's onPictureInPictureModeChanged()
method like this:
// When the app enters or exits PiP mode, the Android system calls this method
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
// Ensure any system-level PiP mode changes are handled correctly
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
// Handle any application-specific behavior related to PiP mode changes and your flowplayer object
flowplayer.onPictureInPictureModeChanged(isInPictureInPictureMode)
}