Last active
August 29, 2022 10:38
-
-
Save Skyyo/2305a669e6f1698d2d121c10e913730b to your computer and use it in GitHub Desktop.
This file contains 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
@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