add back button to player

This commit is contained in:
2026-08-15 17:21:07 +03:00
parent b8234253d3
commit 3e980840b4
4 changed files with 26 additions and 21 deletions
@@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -58,6 +59,7 @@ import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.painterResource
import ru.shadowsparky.ui.components.BackButton
import ru.shadowsparky.ui.components.IconButton
import ru.shadowsparky.ui.components.isTv
import ru.shadowsparky.ui.theme.focusBorder
@@ -74,7 +76,8 @@ fun DefaultControls(
state: PlayerState,
controlsState: ControlsState,
controller: PlayerController,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
onBack: () -> Unit
) {
val isTv = isTv()
val scope = rememberCoroutineScope()
@@ -93,7 +96,11 @@ fun DefaultControls(
modifier = modifier
.fillMaxSize()
.background(if (isUiLocked.value) Color.Transparent else Color.Black.copy(alpha = 0.4f))
.safeDrawingPadding()
) {
Box(modifier = Modifier.align(Alignment.TopStart).padding(8.dp)) {
BackButton { onBack() }
}
SideDoubleTapSeekZones(controller)
Row(modifier = Modifier.align(Alignment.TopEnd).focusGroup().padding(8.dp)) {
if (audioTracksState.isNotEmpty() && !isUiLocked.value) {
@@ -45,13 +45,20 @@ import ru.shadowsparky.videoplayer.ControlsState
import ru.shadowsparky.videoplayer.PlayerController
import ru.shadowsparky.videoplayer.PlayerEvent
import ru.shadowsparky.videoplayer.PlayerState
import kotlin.time.Duration.Companion.seconds
@Composable
fun VideoPlayer(
controller: PlayerController,
modifier: Modifier = Modifier,
onBack: () -> Unit,
overlayContent: @Composable (PlayerState, ControlsState) -> Unit = { player, controls ->
DefaultControls(player, controls, controller = controller)
DefaultControls(
player,
controls,
controller = controller,
onBack = onBack
)
}
) {
val isTv = isTv()
@@ -86,7 +93,7 @@ fun VideoPlayer(
LaunchedEffect(areControlsVisible, state.isPlaying, lastErrorMessage, interactionCount) {
if (areControlsVisible && state.isPlaying && lastErrorMessage == null) {
delay(5000)
delay(5.seconds)
areControlsVisible = false
}
}