android - Issue playing videos on jetpack compose tv app - Stack Overflow

I have an android tv app that am supposed to play some videos. The player am using is Exo player from m

I have an android tv app that am supposed to play some videos. The player am using is Exo player from media3 as recomended by google. The problem is when i test on an emulator the video plays properly but when i test on a real tv device the player displays a white screen but you can hear the audio.

class MainActivity : ComponentActivity() {
@OptIn(UnstableApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setContent {

        val context = LocalContext.current

        val exoPlayer = ExoPlayer.Builder(context)
            .setRenderersFactory(DefaultRenderersFactory(context))
            .build().apply {
                playWhenReady = true
            }

        TeleTheme {
            Surface(
                modifier = Modifier
                    .fillMaxSize()
                    .background(Color.Red),
            ) {
                ExoPlayerView(exoPlayer)
            }
        }
    }
}

Player implementation

@OptIn(UnstableApi::class)
@Composable
fun ExoPlayerView(exoPlayer: ExoPlayer) {
    val mediaSource = remember {
        MediaItem.fromUri(".mp4")
    }

    LaunchedEffect(mediaSource) {
        exoPlayer.setMediaItem(mediaSource)
        exoPlayer.prepare()
    }

    DisposableEffect(Unit) {
        onDispose {
            exoPlayer.release()
        }
    }

    Box(modifier = Modifier
        .fillMaxSize()
        .background(Color.Black), contentAlignment = Alignment.CenterStart) {
            AndroidView(
                modifier = Modifier.fillMaxSize(0.8f),
                factory = { ctx ->
                    PlayerView(ctx).apply {
                        player = exoPlayer
                        useController = true
                        resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
                    }
                },
            )

    }
}

The tv device am testing with is a TCL TV android 11. Anyone who might have a solution to this issue kindly help

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745210829a4616828.html

相关推荐

  • android - Issue playing videos on jetpack compose tv app - Stack Overflow

    I have an android tv app that am supposed to play some videos. The player am using is Exo player from m

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信