ActivityPipHandler

Ready-made PipHandler for the common case: drives the activity's picture-in-picture parameters from the player state OGPlayerView feeds it, auto-enters PiP when the user leaves the app (see OGPlayerView's autoEnterPipOnBackground), and exposes one play/pause remote action on the PiP window.

Host requirements:

  • The player's activity must declare android:supportsPictureInPicture="true" (and the usual android:configChanges for PiP's size/orientation changes) in the manifest. A missing flag is caught: the handler logs the fix once and disables itself instead of crashing.

  • activity must be an androidx ComponentActivity (any AppCompat / Compose activity qualifies) — PiP mode and user-leave observation come from its androidx.core listener registries.

On API 31+ auto-enter uses the platform's seamless setAutoEnterEnabled; on API 26–30 it is approximated via the user-leave hint. The play/pause remote action's broadcast receiver is registered only while in PiP.

Constructors

Link copied to clipboard
constructor(activity: Activity, player: OGPlayer, showPlayPauseAction: Boolean = true)

Properties

Link copied to clipboard
open override var isInPip: Boolean

True while the activity is in picture-in-picture mode.

Functions

Link copied to clipboard
open override fun addPipListener(listener: PipListener)
Link copied to clipboard
open override fun enterPip(): Boolean

Enters picture-in-picture now (e.g. from a custom action or a host button). Returns false when the device/host cannot enter PiP.

Link copied to clipboard
open override fun onPipStateChanged(state: PipVideoState)

Called by OGPlayerView whenever the video state relevant to PiP changes — implementations use it to keep the system's PiP parameters (aspect ratio, source bounds, auto-enter) current. Not host-app API.

Link copied to clipboard
open override fun release()

Detaches the handler from the activity and player and clears the activity's auto-enter arming. A handler is one player screen's companion, not the activity's: call this when that screen closes while the activity lives on (single-activity/navigation apps) — otherwise the activity stays armed and leaving the app from an unrelated screen still drops it into a PiP window. Terminal and idempotent; runs automatically when the activity is destroyed.

Link copied to clipboard
open override fun removePipListener(listener: PipListener)