Skip to content

Commit 9b49d79

Browse files
committed
[ISSUE-68] Adding Player tracker support and preview badge
1 parent 873caf5 commit 9b49d79

File tree

1 file changed

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

1 file changed

+48
-53
lines changed

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

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.codandotv.streamplayerapp.core_shared_ui.widget
22

3-
import androidx.annotation.DrawableRes
4-
import androidx.annotation.StringRes
3+
import androidx.compose.foundation.background
54
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.Row
67
import androidx.compose.foundation.layout.fillMaxWidth
7-
import androidx.compose.material3.Icon
8-
import androidx.compose.material3.IconButton
9-
import androidx.compose.material3.Slider
8+
import androidx.compose.foundation.layout.height
9+
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.material3.MaterialTheme
1011
import androidx.compose.runtime.Composable
1112
import androidx.compose.runtime.DisposableEffect
1213
import androidx.compose.runtime.LaunchedEffect
@@ -18,22 +19,17 @@ import androidx.compose.runtime.setValue
1819
import androidx.compose.ui.Alignment
1920
import androidx.compose.ui.Modifier
2021
import androidx.compose.ui.platform.LocalContext
21-
import androidx.compose.ui.res.painterResource
22-
import androidx.compose.ui.res.stringResource
22+
import androidx.compose.ui.unit.dp
2323
import androidx.compose.ui.viewinterop.AndroidView
2424
import androidx.media3.common.MediaItem
2525
import androidx.media3.common.Player
2626
import androidx.media3.exoplayer.ExoPlayer
2727
import androidx.media3.ui.PlayerView
28-
import com.codandotv.streamplayerapp.core.shared.ui.R
2928
import com.codandotv.streamplayerapp.core_shared_ui.theme.ThemePreviews
29+
import com.codandotv.streamplayerapp.core_shared_ui.widget.player.PlayerTracker
30+
import com.codandotv.streamplayerapp.core_shared_ui.widget.player.PreviewBadge
3031
import kotlinx.coroutines.delay
3132

32-
data class PlayerIconData(
33-
@DrawableRes val iconRes: Int,
34-
@StringRes val contentDescriptionRes: Int,
35-
)
36-
3733
@Composable
3834
fun PlayerComponent(url: String, modifier: Modifier = Modifier) {
3935
val context = LocalContext.current
@@ -42,16 +38,6 @@ fun PlayerComponent(url: String, modifier: Modifier = Modifier) {
4238

4339
var playerPosition by remember { mutableStateOf(0L) }
4440

45-
val playerControlData by remember {
46-
derivedStateOf {
47-
if (isPlayerPlaying) {
48-
PlayerIconData(R.drawable.ic_pause, R.string.player_pause)
49-
} else {
50-
PlayerIconData(R.drawable.ic_play, R.string.player_continue)
51-
}
52-
}
53-
}
54-
5541
val exoplayer = remember {
5642
val mediaItem = MediaItem.Builder()
5743
.setUri(url)
@@ -77,44 +63,53 @@ fun PlayerComponent(url: String, modifier: Modifier = Modifier) {
7763
derivedStateOf { (playerPosition / exoplayer.contentDuration.toDouble()).toFloat() }
7864
}
7965

80-
Box(modifier = modifier) {
81-
AndroidView(
82-
modifier = Modifier
83-
.fillMaxWidth()
84-
.align(Alignment.Center),
85-
factory = {
86-
PlayerView(it).apply {
87-
player = exoplayer
88-
useController = false
89-
}
90-
}
91-
)
92-
93-
IconButton(
94-
modifier = Modifier.align(Alignment.Center),
95-
onClick = {
96-
if (isPlayerPlaying) {
97-
exoplayer.pause()
98-
} else {
99-
exoplayer.play()
66+
Column(
67+
modifier = modifier
68+
.height(225.dp)
69+
.fillMaxWidth()
70+
) {
71+
Box {
72+
AndroidView(
73+
modifier = Modifier
74+
.fillMaxWidth()
75+
.height(200.dp)
76+
.align(Alignment.TopCenter),
77+
factory = {
78+
PlayerView(it).apply {
79+
player = exoplayer
80+
useController = false
81+
}
10082
}
101-
}
102-
) {
103-
Icon(
104-
painter = painterResource(id = playerControlData.iconRes),
105-
contentDescription = stringResource(id = playerControlData.contentDescriptionRes)
83+
)
84+
85+
PreviewBadge(
86+
modifier = Modifier
87+
.align(Alignment.BottomStart)
88+
.padding(
89+
start = 8.dp,
90+
bottom = 8.dp
91+
)
10692
)
10793
}
10894

109-
Slider(
95+
Row(
11096
modifier = Modifier
11197
.fillMaxWidth()
112-
.align(Alignment.BottomCenter),
113-
value = playerProgress,
114-
onValueChange = {}
115-
)
98+
.height(25.dp)
99+
.background(MaterialTheme.colorScheme.background)
100+
) {
101+
PlayerTracker(
102+
modifier = Modifier
103+
.fillMaxWidth()
104+
.height(18.dp)
105+
.padding(horizontal = 0.dp),
106+
percentage = playerProgress,
107+
expanded = false
108+
)
109+
}
116110
}
117111

112+
118113
LaunchedEffect(
119114
key1 = isPlayerPlaying,
120115
block = {

0 commit comments

Comments
 (0)