Skip to content

Instantly share code, notes, and snippets.

@rubenquadros
Created September 4, 2021 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubenquadros/77c6c844359bfc0a0e17c3f20e610389 to your computer and use it in GitHub Desktop.
Save rubenquadros/77c6c844359bfc0a0e17c3f20e610389 to your computer and use it in GitHub Desktop.
Playing videos in the video player
@Composable
fun VideoPlayer(
modifier: Modifier = Modifier,
gameVideos: List<VideoResultEntity>
) {
val context = LocalContext.current
val mediaItems = arrayListOf<MediaItem>()
// create MediaItem
gameVideos.forEach {
mediaItems.add(
MediaItem.Builder()
.setUri(it.video)
.setMediaId(it.id.toString())
.setTag(it)
.setMediaMetadata(
MediaMetadata.Builder()
.setDisplayTitle(it.name)
.build()
)
.build()
)
}
val exoPlayer = remember {
SimpleExoPlayer.Builder(context).build().apply {
this.setMediaItems(mediaItems)
this.prepare()
this.playWhenReady = true
}
}
// views same as above code snippet
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment