Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Composable
fun VideosScreen(viewModel: VideosViewModel = hiltViewModel()) {
val context = LocalContext.current
val exoPlayer = remember(context) { SimpleExoPlayer.Builder(context).build() }
val videos by viewModel.videos.observeAsState()
val playingItemIndex by viewModel.currentlyPlayingIndex.observeAsState()
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