PictureInPictureUiStateCompat


class PictureInPictureUiStateCompat


A compatibility shim for the framework class PictureInPictureUiState. This class is safe to reference across all API levels.

Summary

Public constructors

PictureInPictureUiStateCompat(
    isStashed: Boolean,
    isTransitioningToPip: Boolean
)

Public properties

Boolean

Returns whether Picture-in-Picture is stashed or not.

Boolean

Returns true if the app is going to enter Picture-in-Picture (PiP) mode.

Public companion functions

Public constructors

PictureInPictureUiStateCompat

PictureInPictureUiStateCompat(
    isStashed: Boolean,
    isTransitioningToPip: Boolean
)

Public properties

isStashed

val isStashedBoolean

Returns whether Picture-in-Picture is stashed or not. A stashed PiP means it is only partially visible to the user, with some parts of it being off-screen. This is usually a UI state that is triggered by the user, such as flinging the PiP to the edge or letting go of PiP while dragging partially off-screen.

Developers can use this in conjunction with OnPictureInPictureUiStateChangedProvider to get a signal when the PiP stash state has changed. For example, if the state changed from false to true, developers can choose to temporarily pause video playback if PiP is of video content. Vice versa, if changing from true to false and video content is paused, developers can resume video playback.

Compatibility notes: this value is meaningful on API 31+

isTransitioningToPip

val isTransitioningToPipBoolean

Returns true if the app is going to enter Picture-in-Picture (PiP) mode.

This state is associated with the entering PiP animation. When that animation starts, whether via auto enter PiP or calling ComponentActivity.enterPictureInPictureMode explicitly, app can expect ComponentActivity.onPictureInPictureUiStateChanged callback with isTransitioningToPip to be true first, followed by ComponentActivity.onPictureInPictureModeChanged when it fully settles in PiP mode.

When app receives the ComponentActivity.onPictureInPictureUiStateChanged callback with isTransitioningToPip being true, it's recommended to hide certain UI elements, such as video controls, to archive a clean entering PiP animation.

In case an application wants to restore the previously hidden UI elements when exiting PiP, it is recommended to do that in ComponentActivity.onPictureInPictureUiStateChanged callback when isTransitioningToPip is false, rather than the beginning of exit PiP animation.

Compatibility notes: this value is meaningful on API 35+