Kotlin
Launching Picture-in-Picture
1. Add a Button to Enter Picture-in-Picture
Hide the button while already in PiP. Wire it from VideoCallScreen:
Copy
if (!isInPipMode) {
Button(
onClick = onEnterPictureInPicture,
modifier = Modifier.align(Alignment.TopStart).padding(8.dp),
) {
Text("Enter Picture-In-Picture")
}
}
2. Enter PiP with Aspect Ratio and Device Checks
Use PictureInPictureParams on API 26+ and verify the device supports PiP:
Copy
private fun enterPictureInPicture() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
Toast.makeText(this, "Picture-in-picture is not supported on this device.", Toast.LENGTH_SHORT)
.show()
return
}
if (!packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
Toast.makeText(this, "Picture-in-picture is not supported on this device.", Toast.LENGTH_SHORT)
.show()
return
}
try {
val params = PictureInPictureParams.Builder()
.setAspectRatio(Rational(9, 16))
.build()
enterPictureInPictureMode(params)
} catch (e: IllegalStateException) {
Log.e(TAG, "Failed to enter picture-in-picture mode", e)
Toast.makeText(this, "Could not enter picture-in-picture mode.", Toast.LENGTH_SHORT).show()
}
}
Adjust Rational(width, height) to match your preferred PiP window shape (the sample uses portrait 9:16).
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