JetPack Compose-超级盖子全屏
我正在尝试在用JetPack Compose制造的Android应用中蒸展视频。要流媒体播放我,但我真的不明白如何实现全屏按钮,一些建议?
@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 props exo将显示全屏的构建按钮,我解决了我的问题,呼叫此listner中的全屏幕功能
AndroidView(
factory = { context ->
StyledPlayerView(context).apply {
player = mExoPlayer
setControllerOnFullScreenModeChangedListener {
if(it)
//fullscreen
else
//minimize
} }
})
i am trying to steam a video in my android app made with jetpack compose. To stream i using ExoPlayer but i can't really understand how to implement a full screen button, some advice?
@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()
}
}
}
Edit
Adding the setControllerOnFullScreenModeChangedListener props exo will show a build in button for the fullscreen, i solved my problem calling the full screen function inside this listner
AndroidView(
factory = { context ->
StyledPlayerView(context).apply {
player = mExoPlayer
setControllerOnFullScreenModeChangedListener {
if(it)
//fullscreen
else
//minimize
} }
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用此代码
使用此扩展功能查找活动实例:
设置屏幕方向使用以下扩展功能:
最后将此功能用于hide/show system ui(状态栏):
use this code
use this extension function for find activity instance:
to set screen orientation use below extension function:
and finally use this functions for hide/show system ui (status bar):
要使应用程序全屏进行全屏,
我对Kotlin量身定制的应用程序,因此您需要做的就是将其挂在
button
's onclick 和你很好。如果由于某种原因不起作用,或者无法通过
onclick
无法访问某些内容,只需使用使用
mutableState< boolean>
作为钥匙并更改键以触发反应。不需要,很可能是因为OnClick
应该正常工作。To make an app go full-screen, there's
Which I've tailored to Kotlin, so all you need to do is just hook it up in a
Button
'sonClick
and you're good to go.If this does not work for some reason, or something is not accessible through the
onClick
, just create aLaunchedEffect
with aMutableState<Boolean>
as the key and change the key to trigger the reaction. Won't be necessary, most probably since theonClick
should work just fine.我有一个示例,该示例实现了完整屏幕,用 compose-media 。您不必使用此库。但是解决方案是相似的。
mediacontent
,您可以将全屏切换相对逻辑封装在其中。以下代码将类似于YouTube的全屏切换行为(不是UI)。您可以在此处找到完整的代码: https://github.com/fengdai/fengdai/compose-media/blob/blob/master/sample/sample/sramplc/src/main/java/java/java/java/github/github/github/fengdai/compose /Media/sample/fullspreeentoggle.kt
I have an example which implements fullscreen toggling with compose-media. You don't have to use this library. But the solution is similar.
MediaContent
for media playback, and you can encapsulate fullscreen toggling relative logic inside it. Below code will work similar to YouTube's fullscreen toggling behavior (not UI).You can find full code here: https://github.com/fengdai/compose-media/blob/master/sample/src/main/java/com/github/fengdai/compose/media/sample/FullscreenToggle.kt