首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jetpack作曲中的图景

Jetpack作曲中的图景
EN

Stack Overflow用户
提问于 2022-08-08 07:48:17
回答 2查看 226关注 0票数 0

我刚开始写作。是否有一种处理jetpack撰写中的picture-in-picture模式的方法?我找不到任何与此相关的官方文件。

EN

回答 2

Stack Overflow用户

发布于 2022-08-08 08:22:00

Android有一个指南用于图片中的图片,并在javaKotlin中使用示例代码。

这不是在喷气背包的组成。

票数 0
EN

Stack Overflow用户

发布于 2022-09-19 10:31:00

代码语言:javascript
复制
class MainActivity : ComponentActivity() {

class MyReciever:BroadcastReceiver(){
    override fun onReceive(context: Context?, intent: Intent?) {
       println("clicked on PIP action")
    }

}

private val isPipSupported by lazy {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        packageManager.hasSystemFeature(
            PackageManager.FEATURE_PICTURE_IN_PICTURE
        )
    } else {
        false
    }
}
private var videoViewBounds = Rect()

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
        PictureInPictureTheme {
            /***
             * video view does't exit for compose.
             * So we use android view
             * and in factory we create video view and use apply to assign video.
             */
            AndroidView(
                factory ={
                    VideoView(it,null).apply {
                        setVideoURI(Uri.parse("android.resource://$packageName/${R.raw.lakshay}"))
                            start()
                    }
                } ,
                modifier = Modifier
                    .fillMaxWidth()
                    .onGloballyPositioned {
                        videoViewBounds = it
                            .boundsInWindow()
                            .toAndroidRect()
                    }
            )

        }
    }
}
private fun updatedPipParams(): PictureInPictureParams?{
    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        PictureInPictureParams.Builder()
            .setSourceRectHint(videoViewBounds)
            .setAspectRatio(Rational(16,9))
            .setActions(
                listOf(
                    RemoteAction(
                    android.graphics.drawable.Icon.createWithResource(applicationContext,
                    R.drawable.ic_baseline_baby_changing_station_24),
                        "Baby Changing Station",
                        "Baby Changing Station",
                        PendingIntent.getBroadcast(
                            applicationContext,
                            0,
                            Intent(applicationContext,MyReciever::class.java),
                            PendingIntent.FLAG_IMMUTABLE
                        )
                    )
                )
            )
            .build()
    } else {
        TODO("VERSION.SDK_INT < O")
    }
}

override fun onUserLeaveHint() {
    super.onUserLeaveHint()
    if(!isPipSupported){
        return
    }
    updatedPipParams()?.let {params->
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            enterPictureInPictureMode(params)
        }
    }

}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73274447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档