Kotlin
Managing PiP Mode Changes
1. Update the UI When PiP Mode Changes
Override onPictureInPictureModeChanged to track PiP state and hide the local preview in the floating window (subscriber video remains):
override fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration,
) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
isInPipMode = isInPictureInPictureMode
if (isInPictureInPictureMode) {
publisherViewContainer.visibility = View.GONE
publisher?.view?.visibility = View.GONE
} else {
publisherViewContainer.visibility = View.VISIBLE
publisher?.view?.visibility = View.VISIBLE
if (publisher?.view is GLSurfaceView) {
(publisher?.view as GLSurfaceView).setZOrderOnTop(true)
}
}
}
Expose isInPipMode to Compose (for example with mutableStateOf) so the PiP button hides automatically.
2. Keep the Session Alive in PiP
Do not call session.onPause() while in PiP, or the call may pause when the user leaves the full-screen activity:
override fun onPause() {
super.onPause()
if (!isInPictureInPictureMode) {
session?.onPause()
}
}
override fun onResume() {
super.onResume()
if (!isInPictureInPictureMode) {
session?.onResume()
}
}
3. Clean Up Views in onStop
Remove publisher and subscriber views when the activity stops:
override fun onStop() {
super.onStop()
subscriber?.let { subscriberViewContainer.removeView(it.view) }
publisher?.let { publisherViewContainer.removeView(it.view) }
}
Picture in Picture
Learn how add Picture in Picture functionality to your app using Vonage Video SDK.
Available on:
Steps
1
Introduction2
Getting Started3
Creating a New Project4
Adding the Android SDK5
Setting Up Authentication6
Requesting Permissions7
Enable Picture-in-Picture on Your Activity8
Provide Containers for Video Views9
Launching Picture-in-Picture10
Managing PiP Mode Changes11
Running the App12
Conclusion