通过按钮添加画中画

如需通过点击按钮进入画中画模式,请对 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!")
}