通过按钮添加画中画 (PiP)

要通过按钮点击进入画中画 (PiP) 模式,请在 findActivity() 上调用 enterPictureInPictureMode()

参数已通过之前对 PictureInPictureParams.Builder 的调用设置,因此您无需在构建器上设置新参数。但是,如果您希望在按钮点击时更改任何参数,可以在此处设置它们。

val context = LocalContext.current
Button(onClick = {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        context.findActivity().enterPictureInPictureMode(
            PictureInPictureParams.Builder().build()
        )
    } else {
        Log.i(PIP_TAG, "API does not support PiP")
    }
}) {
    Text(text = "Enter PiP mode!")
}