About picture-in-picture (PiP)
Stay organized with collections
Save and categorize content based on your preferences.
Picture-in-picture (PiP) is a special type of multi-window mode mostly used for
video playback. It lets the user watch a video in a small window pinned to a
corner of the screen while navigating between apps or browsing content on the
main screen.
PiP leverages the multi-window APIs made available in Android 7.0 to provide the
pinned video overlay window. To add PiP to your app, you need to register your
activity, switch your activity to PiP mode as needed, and make sure UI elements
are hidden and video playback continues when the activity is in PiP mode.
Handle your UI in PiP mode
When you enter PiP mode, your app's entire UI enters the PiP window unless you
specify how your UI should look in and out of PiP mode.
First, you need to know when your app is in PiP mode or not. You can use
OnPictureInPictureModeChangedProvider
to achieve this.
The code below tells you if your app is in PiP mode.
@Composable
fun rememberIsInPipMode(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val activity = LocalContext.current.findActivity()
var pipMode by remember { mutableStateOf(activity.isInPictureInPictureMode) }
DisposableEffect(activity) {
val observer = Consumer<PictureInPictureModeChangedInfo> { info ->
pipMode = info.isInPictureInPictureMode
}
activity.addOnPictureInPictureModeChangedListener(
observer
)
onDispose { activity.removeOnPictureInPictureModeChangedListener(observer) }
}
return pipMode
} else {
return false
}
}
Now, you can use rememberIsInPipMode()
to toggle which UI elements to show
when the app enters PiP mode:
val inPipMode = rememberIsInPipMode()
Column(modifier = modifier) {
// This text will only show up when the app is not in PiP mode
if (!inPipMode) {
Text(
text = "Picture in Picture",
)
}
VideoPlayer()
}
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-05-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-05-20 UTC."],[],[],null,["# About picture-in-picture (PiP)\n\nPicture-in-picture (PiP) is a special type of multi-window mode mostly used for\nvideo playback. It lets the user watch a video in a small window pinned to a\ncorner of the screen while navigating between apps or browsing content on the\nmain screen.\n\nPiP leverages the multi-window APIs made available in Android 7.0 to provide the\npinned video overlay window. To add PiP to your app, you need to register your\nactivity, switch your activity to PiP mode as needed, and make sure UI elements\nare hidden and video playback continues when the activity is in PiP mode.\n\nHandle your UI in PiP mode\n--------------------------\n\nWhen you enter PiP mode, your app's entire UI enters the PiP window unless you\nspecify how your UI should look in and out of PiP mode.\n\nFirst, you need to know when your app is in PiP mode or not. You can use\n[`OnPictureInPictureModeChangedProvider`](/reference/androidx/core/app/OnPictureInPictureModeChangedProvider) to achieve this.\nThe code below tells you if your app is in PiP mode.\n\n\n```kotlin\n@Composable\nfun rememberIsInPipMode(): Boolean {\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.O) {\n val activity = LocalContext.current.findActivity()\n var pipMode by remember { mutableStateOf(activity.isInPictureInPictureMode) }\n DisposableEffect(activity) {\n val observer = Consumer\u003cPictureInPictureModeChangedInfo\u003e { info -\u003e\n pipMode = info.isInPictureInPictureMode\n }\n activity.addOnPictureInPictureModeChangedListener(\n observer\n )\n onDispose { activity.removeOnPictureInPictureModeChangedListener(observer) }\n }\n return pipMode\n } else {\n return false\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/pictureinpicture/PictureInPictureSnippets.kt#L119-L137\n```\n\n\u003cbr /\u003e\n\nNow, you can use `rememberIsInPipMode()` to toggle which UI elements to show\nwhen the app enters PiP mode:\n\n\n```kotlin\nval inPipMode = rememberIsInPipMode()\n\nColumn(modifier = modifier) {\n // This text will only show up when the app is not in PiP mode\n if (!inPipMode) {\n Text(\n text = \"Picture in Picture\",\n )\n }\n VideoPlayer()\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/pictureinpicture/PictureInPictureSnippets.kt#L152-L162\n```\n\n\u003cbr /\u003e"]]