Skip to content

Commit 1fe6849

Browse files
committed
[ISSUE-68] - Player customization
- Base listener to decide if it is playing or not; - Slider to represent the progress.
1 parent 92c9b6c commit 1fe6849

File tree

1 file changed

+27
-11
lines changed
  • core-shared-ui/src/main/java/com/codandotv/streamplayerapp/core_shared_ui/widget

1 file changed

+27
-11
lines changed

core-shared-ui/src/main/java/com/codandotv/streamplayerapp/core_shared_ui/widget/PlayerComponent.kt

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Box
66
import androidx.compose.foundation.layout.fillMaxWidth
77
import androidx.compose.material3.Icon
88
import androidx.compose.material3.IconButton
9+
import androidx.compose.material3.Slider
910
import androidx.compose.runtime.Composable
1011
import androidx.compose.runtime.DisposableEffect
1112
import androidx.compose.runtime.derivedStateOf
@@ -20,6 +21,7 @@ import androidx.compose.ui.res.painterResource
2021
import androidx.compose.ui.res.stringResource
2122
import androidx.compose.ui.viewinterop.AndroidView
2223
import androidx.media3.common.MediaItem
24+
import androidx.media3.common.Player
2325
import androidx.media3.exoplayer.ExoPlayer
2426
import androidx.media3.ui.PlayerView
2527
import com.codandotv.streamplayerapp.core.shared.ui.R
@@ -38,6 +40,16 @@ fun PlayerComponent(url: String, modifier: Modifier = Modifier) {
3840
mutableStateOf(true)
3941
}
4042

43+
val playerControlData by remember {
44+
derivedStateOf {
45+
if (isPlayerPlaying) {
46+
PlayerIconData(R.drawable.ic_pause, R.string.player_pause)
47+
} else {
48+
PlayerIconData(R.drawable.ic_play, R.string.player_continue)
49+
}
50+
}
51+
}
52+
4153
val exoplayer = remember {
4254
val mediaItem = MediaItem.Builder()
4355
.setUri(url)
@@ -48,19 +60,17 @@ fun PlayerComponent(url: String, modifier: Modifier = Modifier) {
4860
prepare()
4961

5062
playWhenReady = true
51-
}
52-
}
5363

54-
val playerControlData by remember {
55-
derivedStateOf {
56-
if (isPlayerPlaying) {
57-
PlayerIconData(R.drawable.ic_pause, R.string.player_pause)
58-
} else {
59-
PlayerIconData(R.drawable.ic_play, R.string.player_continue)
60-
}
64+
addListener(object : Player.Listener {
65+
override fun onIsPlayingChanged(isPlaying: Boolean) {
66+
isPlayerPlaying = isPlaying
67+
}
68+
})
6169
}
6270
}
6371

72+
var playerProgress = remember { mutableStateOf(0f) }
73+
6474
Box(modifier = modifier) {
6575
AndroidView(
6676
modifier = Modifier
@@ -82,15 +92,21 @@ fun PlayerComponent(url: String, modifier: Modifier = Modifier) {
8292
} else {
8393
exoplayer.play()
8494
}
85-
86-
isPlayerPlaying = isPlayerPlaying.not()
8795
}
8896
) {
8997
Icon(
9098
painter = painterResource(id = playerControlData.iconRes),
9199
contentDescription = stringResource(id = playerControlData.contentDescriptionRes)
92100
)
93101
}
102+
103+
Slider(
104+
modifier = Modifier
105+
.fillMaxWidth()
106+
.align(Alignment.BottomCenter),
107+
value = 0.5f,
108+
onValueChange = {}
109+
)
94110
}
95111

96112
DisposableEffect(key1 = Unit, effect = {

0 commit comments

Comments
 (0)