Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active Aug 29, 2022
Embed
What would you like to do?
@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