Reputation: 23
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("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.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
Upvotes: 0
Views: 42