Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active August 29, 2022 10:38
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 Skyyo/2305a669e6f1698d2d121c10e913730b to your computer and use it in GitHub Desktop.
Save Skyyo/2305a669e6f1698d2d121c10e913730b to your computer and use it in GitHub Desktop.
@Composable
fun VideosScreen(viewModel: VideosViewModel = hiltViewModel()) {
val context = LocalContext.current
val exoPlayer = remember(context) { ExoPlayer.Builder(context).build() }
val videos by viewModel.videos.collectAsStateWithLifecycle()
val playingItemIndex by viewModel.currentlyPlayingIndex.collectAsStateWithLifecycle()
LazyColumn {
itemsIndexed(items = videos, key = { _, video -> video.id }) { index, video ->
VideoCard(
videoItem = video,
exoPlayer = exoPlayer,
isPlaying = index == playingItemIndex,
onClick = {
viewModel.onPlayVideoClick(exoPlayer.currentPosition, index)
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment