Can't interact with ExoPlayer using Jetpack Compose on Android TV
Open
@marcbaechinger is already working on this.
Since Jun 13, 2023.
documentation candidate
question
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Media3 Version
ExoPlayer 2.18.7
Devices that reproduce the issue
Emulator running Android TV API 31
Devices that do not reproduce the issue
None
Reproducible in the demo app?
Yes
Reproduction steps
Using androidx.tv version 1.0.0-alpha06 with the following composable (adding focusable and focusRequester were my attempts to fix it):
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun VideoPlayer(mediaItem: VideoApi.MediaItem) {
val (playerFocus) = remember { FocusRequester.createRefs() }
val context = LocalContext.current
val exoPlayer = remember {
ExoPlayer.Builder(context)
.build()
.apply {
addMediaItem(
MediaItem.Builder()
.setUri(mediaItem.hlsCaptions)
.setMimeType(MimeTypes.APPLICATION_M3U8)
.build()
)
prepare()
playWhenReady = true
}
}
LaunchedEffect(Unit) {
playerFocus.requestFocus()
}
DisposableEffect(
AndroidView(
modifier = Modifier
.focusable(true)
.focusRequester(playerFocus),
factory = {
StyledPlayerView(context).apply {
player = exoPlayer
useController = true
controllerAutoShow = true
setShowBuffering(StyledPlayerView.SHOW_BUFFERING_ALWAYS)
}
}
)
) {
onDispose {
exoPlayer.release()
}
}
}
Expected result
Should be able to interact, i.e. D-pad should bring up video HUD controls.
Actual result
Any key presses (besides back) do nothing.
Media
Any media should show it. I'm using an HLS stream. For example:
https://m.wsj.net/video/20230531/eaa54145-d07a-4100-8153-2eaf8d671921/1/hls/manifest-hd-wifi.m3u8
Bug Report
- You will email the zip file produced by
adb bugreportto dev.exoplayer@gmail.com after filing this issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.