Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

426 add some spaces to position indicator #444

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderColors
Expand All @@ -21,6 +22,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.media3.common.C
import androidx.media3.common.Player
import ch.srgssr.pillarbox.demo.shared.ui.getFormatter
import ch.srgssr.pillarbox.demo.ui.theme.paddings
Expand All @@ -33,6 +35,7 @@ import ch.srgssr.pillarbox.ui.extension.availableCommandsAsState
import ch.srgssr.pillarbox.ui.extension.currentBufferedPercentageAsState
import ch.srgssr.pillarbox.ui.extension.durationAsState
import kotlinx.coroutines.CoroutineScope
import kotlin.time.Duration.Companion.ZERO
import kotlin.time.Duration.Companion.milliseconds

/**
Expand Down Expand Up @@ -73,18 +76,22 @@ fun PlayerTimeSlider(
progressTracker: ProgressTrackerState = rememberProgressTrackerState(player = player, smoothTracker = true),
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
val duration by player.durationAsState()
val durationMs by player.durationAsState()
val duration = remember(durationMs) {
if (durationMs == C.TIME_UNSET) ZERO
else durationMs.milliseconds
}
val currentProgress by progressTracker.progress.collectAsState()
val currentProgressPercent = currentProgress.inWholeMilliseconds / player.duration.coerceAtLeast(1).toFloat()
val bufferPercentage by player.currentBufferedPercentageAsState()
val availableCommands by player.availableCommandsAsState()
val formatter = duration.milliseconds.getFormatter()
val formatter = duration.getFormatter()
Row(
modifier = modifier,
modifier = modifier.padding(horizontal = MaterialTheme.paddings.mini),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.paddings.mini)
) {
Text(text = formatter(currentProgress))
Text(text = formatter(currentProgress), color = Color.White)
Box(modifier = Modifier.weight(1f)) {
Slider(
value = bufferPercentage,
Expand All @@ -104,7 +111,7 @@ fun PlayerTimeSlider(
interactionSource = interactionSource,
)
}
Text(text = formatter(duration.milliseconds))
Text(text = formatter(duration), color = Color.White)
}
}

Expand Down
Loading