Skip to content

Instantly share code, notes, and snippets.

@itsSiddharthGupta
Created March 27, 2025 18:10
Show Gist options
  • Save itsSiddharthGupta/945cbd992d24c103975e438ac5c65f05 to your computer and use it in GitHub Desktop.
Save itsSiddharthGupta/945cbd992d24c103975e438ac5c65f05 to your computer and use it in GitHub Desktop.
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.example.explore.player.ui.VideoPlayer
import com.example.exoplayerpool.ExoPlayerManager
import com.example.exoplayerpool.controller.ExoPlayerController
import com.example.exoplayerpool.core.MediaSource
import java.util.UUID
@Composable
fun VideoList(playerManager: ExoPlayerManager) {
val listState = rememberLazyListState()
LazyColumn(state = listState) {
items(10) { index ->
VideoItem(playerManager, index)
}
}
}
@Composable
fun VideoItem(playerManager: ExoPlayerManager, index: Int) {
val singleController: ExoPlayerController = remember {
playerManager.createPlayerController(UUID.randomUUID().toString())
}
Column(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
.trackVisibility(thresholdPercentage = 0.7f) { visibilityInfo ->
if (visibilityInfo.isAboveThreshold) {
singleController.play()
} else {
singleController.pause()
}
}
) {
VideoPlayer(
controller = singleController,
mediaSource = MediaSource.Network("https://ireplay.tv/test/blender.m3u8"),
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxWidth()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment