@@ -9,10 +9,12 @@ import androidx.compose.material3.IconButton
99import androidx.compose.material3.Slider
1010import androidx.compose.runtime.Composable
1111import androidx.compose.runtime.DisposableEffect
12+ import androidx.compose.runtime.LaunchedEffect
1213import androidx.compose.runtime.derivedStateOf
1314import androidx.compose.runtime.getValue
1415import androidx.compose.runtime.mutableStateOf
1516import androidx.compose.runtime.remember
17+ import androidx.compose.runtime.rememberCoroutineScope
1618import androidx.compose.runtime.setValue
1719import androidx.compose.ui.Alignment
1820import androidx.compose.ui.Modifier
@@ -26,6 +28,8 @@ import androidx.media3.exoplayer.ExoPlayer
2628import androidx.media3.ui.PlayerView
2729import com.codandotv.streamplayerapp.core.shared.ui.R
2830import com.codandotv.streamplayerapp.core_shared_ui.theme.ThemePreviews
31+ import kotlinx.coroutines.delay
32+ import kotlinx.coroutines.launch
2933
3034data class PlayerIconData (
3135 @DrawableRes val iconRes : Int ,
@@ -36,9 +40,9 @@ data class PlayerIconData(
3640fun PlayerComponent (url : String , modifier : Modifier = Modifier ) {
3741 val context = LocalContext .current
3842
39- var isPlayerPlaying by remember {
40- mutableStateOf( true )
41- }
43+ var isPlayerPlaying by remember { mutableStateOf( true ) }
44+
45+ var playerPosition by remember { mutableStateOf( 0L ) }
4246
4347 val playerControlData by remember {
4448 derivedStateOf {
@@ -61,15 +65,21 @@ fun PlayerComponent(url: String, modifier: Modifier = Modifier) {
6165
6266 playWhenReady = true
6367
64- addListener(object : Player .Listener {
65- override fun onIsPlayingChanged (isPlaying : Boolean ) {
66- isPlayerPlaying = isPlaying
68+ addListener(
69+ object : Player .Listener {
70+ override fun onIsPlayingChanged (isPlaying : Boolean ) {
71+ isPlayerPlaying = isPlaying
72+ }
6773 }
68- } )
74+ )
6975 }
7076 }
7177
72- var playerProgress = remember { mutableStateOf(0f ) }
78+ val playerProgress by remember {
79+ derivedStateOf { (playerPosition / exoplayer.contentDuration.toDouble()).toFloat() }
80+ }
81+
82+ val coroutineScope = rememberCoroutineScope()
7383
7484 Box (modifier = modifier) {
7585 AndroidView (
@@ -104,11 +114,23 @@ fun PlayerComponent(url: String, modifier: Modifier = Modifier) {
104114 modifier = Modifier
105115 .fillMaxWidth()
106116 .align(Alignment .BottomCenter ),
107- value = 0.5f ,
117+ value = playerProgress ,
108118 onValueChange = {}
109119 )
110120 }
111121
122+ LaunchedEffect (
123+ key1 = isPlayerPlaying,
124+ block = {
125+ coroutineScope.launch {
126+ while (isPlayerPlaying) {
127+ delay(500L )
128+ playerPosition + = 500L
129+ }
130+ }
131+ }
132+ )
133+
112134 DisposableEffect (key1 = Unit , effect = {
113135 onDispose {
114136 exoplayer.release()
0 commit comments