gpt4 book ai didi

android-jetpack-compose - Jetpack compose - Exoplayer 全屏

转载 作者:行者123 更新时间:2023-12-05 09:02:04 28 4
gpt4 key购买 nike

我正在尝试在我的 Android 应用程序中使用 Jetpack Compose 播放视频。要使用 ExoPlayer 进行流式传输,但我真的不明白如何实现全屏按钮,有什么建议吗?

@Composable
private fun VideoPlayer() {
val videoURI = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
val httpDataSourceFactory: HttpDataSource.Factory =
DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(false)
val dataSourceFactory: DataSource.Factory = DataSource.Factory {
val dataSource = httpDataSourceFactory.createDataSource()
dataSource.setRequestProperty(
"cookie", "cookieValue"
)
dataSource.setRequestProperty("Range", "1-10000")
dataSource
}

val mContext = LocalContext.current
// Initializing ExoPLayer
val mExoPlayer = remember(mContext) {
ExoPlayer.Builder(mContext)
.setMediaSourceFactory(DefaultMediaSourceFactory(dataSourceFactory)).build().apply {

val mediaItem = MediaItem.Builder()
.setUri(Uri.parse(videoURI))
.build()
setMediaItem(mediaItem)
playWhenReady = true
prepare()

}

}

DisposableEffect(

// Implementing ExoPlayer
AndroidView(factory = { context ->
StyledPlayerView(context).apply {
player = mExoPlayer
}
})
) {
onDispose {
mExoPlayer.release()
}
}
}

编辑添加 setControllerOnFullScreenModeChangedListener Prop exo 将显示全屏的内置按钮,我解决了我在这个监听器中调用全屏功能的问题

            AndroidView(
factory = { context ->
StyledPlayerView(context).apply {
player = mExoPlayer
setControllerOnFullScreenModeChangedListener {
if(it)
//fullscreen
else
//minimize
} }
})

最佳答案

要让应用全屏显示,有

with(WindowCompat.getInsetsController(window, window.decorView)) {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(WindowInsetsCompat.Type.systemBars())
}

这是我为 Kotlin 量身定制的,所以您只需将其连接到 Button 中即可。的 onClick一切顺利。

Button(
onclick = { /*Paste above Code here*/ }
){
Text("Go full-screen") // Whatever here, per your use-case
}

如果由于某种原因这不起作用,或者无法通过 onClick 访问某些内容, 只需创建一个 LaunchedEffectMutableState<Boolean>作为键并更改键以触发 react 。没有必要,很可能是因为 onClick应该工作得很好。

关于android-jetpack-compose - Jetpack compose - Exoplayer 全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72102097/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com