Regarding the reuse of an Android View. Is there any way of unloading resources once the view is destroyed? I want to avoid leaking things.
Alex
04/12/2021, 1:39 PM
Concretely I have the usecase of rendering to a TextureView with ExoPlayer
Copy code
@Composable
fun VideoRenderView(
modifier: Modifier = Modifier,
videoRenderViewModel: VideoRenderViewModel,
update: TextureView.(SimpleExoPlayer) -> Unit,
) {
AndroidView(
factory = { context ->
val textureView = TextureView(context)
val player = videoRenderViewModel.player
player.setVideoTextureView(textureView)
textureView.tag = player
textureView
},
modifier = modifier,
update = {
update(it, it.tag as SimpleExoPlayer)
}
)
}
Within the factory I set the textureView as output to the player. Since the player has a different lifecycle I probably have to unset the textureView (e.g.
player.setVideoTextureView(null)
) somewhere.
Is there a place for those things in compose?
h
Halil Ozercan
04/12/2021, 2:24 PM
you might want to try
DisposableEffect
😎 1
a
Alex
04/13/2021, 7:40 AM
Thanks @Halil Ozercan this looks like exactly what I need