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
评论列表(0条)