Ahmet Delibaş
03/04/2021, 8:15 PMAhmet Delibaş
03/04/2021, 8:17 PM@Composable
fun ViedoPlayer(
url: String,
selected: Boolean = true,
scaleX: Float = 1F,
content: @Composable (SimpleExoPlayer) -> Unit,
) {
val context = AmbientContext.current
val player = remember {
SimpleExoPlayer.Builder(context)
.build()
.apply {
val mediaSource = ProgressiveMediaSource.Factory(
DefaultDataSourceFactory(
context,
Util.getUserAgent(context, context.packageName)
)
).createMediaSource(Uri.parse(url))
this.prepare(mediaSource)
}
}
player.videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
player.repeatMode = Player.REPEAT_MODE_ONE
AndroidView({
PlayerView(it).apply {
this.scaleX = scaleX
this.useController = false
this.player = player
this.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL
}
})
player.playWhenReady = selected
DisposableEffect(Unit) {
onDispose {
player.release()
}
}
content.invoke(player)
}
Here is my question: It's not working, and some people tells use TextureView. How can i do it in Compose UI. (I mean in AndroidView layout)