Last active
September 2, 2024 04:49
-
-
Save AndroBrain/eef94f4ab3d12e01b73f652f2ffa625c to your computer and use it in GitHub Desktop.
VideoSurface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val VIDEO_URL = "https://cdn.pixabay.com/video/2015/08/20/468-136808389_large.mp4" | |
@Composable | |
fun PlayerScreen() { | |
val context = LocalContext.current | |
val exoPlayer = remember { | |
ExoPlayer.Builder(context).build().apply { | |
// Configure the player | |
// here I'm making the video loop | |
repeatMode = ExoPlayer.REPEAT_MODE_ALL | |
playWhenReady = true | |
setMediaItem(MediaItem.fromUri(VIDEO_URL)) | |
prepare() | |
} | |
} | |
VideoSurface(modifier = Modifier.fillMaxSize(), exoPlayer = exoPlayer) | |
} | |
@Composable | |
fun VideoSurface(modifier: Modifier = Modifier, exoPlayer: ExoPlayer) { | |
AndroidExternalSurface( | |
modifier = modifier, | |
onInit = { | |
onSurface { surface, _, _ -> | |
exoPlayer.setVideoSurface(surface) | |
surface.onDestroyed { exoPlayer.setVideoSurface(null) } | |
} | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment