Skip to content

Commit

Permalink
feat: use seek increment from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
yueban committed Aug 29, 2024
1 parent d26c946 commit b4e5a08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/tv/src/main/java/dev/jdtech/jellyfin/ui/PlayerScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ fun VideoPlayerControls(
onSeek = { player.seekTo(player.duration.times(it).toLong()) },
contentProgress = contentCurrentPosition.milliseconds,
contentDuration = player.duration.milliseconds,
seekBackIncrement = player.seekBackIncrement.milliseconds,
seekForwardIncrement = player.seekForwardIncrement.milliseconds,
)
},
mediaActions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.media3.common.C
import androidx.tv.material3.MaterialTheme
import dev.jdtech.jellyfin.ui.theme.FindroidTheme
import dev.jdtech.jellyfin.utils.handleDPadKeyEvents
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.Duration.Companion.milliseconds

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun VideoPlayerSeekBar(
contentProgress: Duration,
contentDuration: Duration,
seekProgressStep: Duration,
seekBackIncrement: Duration,
seekForwardIncrement: Duration,
onSeek: (seekProgress: Float) -> Unit,
state: VideoPlayerState,
) {
Expand Down Expand Up @@ -80,14 +82,14 @@ fun VideoPlayerSeekBar(
},
onLeft = {
if (isSelected) {
seekContentProgress = (seekContentProgress - seekProgressStep).coerceAtLeast(Duration.ZERO)
seekContentProgress = (seekContentProgress - seekBackIncrement).coerceAtLeast(Duration.ZERO)
} else {
focusManager.moveFocus(FocusDirection.Left)
}
},
onRight = {
if (isSelected) {
seekContentProgress = (seekContentProgress + seekProgressStep).coerceAtMost(contentDuration)
seekContentProgress = (seekContentProgress + seekForwardIncrement).coerceAtMost(contentDuration)
} else {
focusManager.moveFocus(FocusDirection.Right)
}
Expand Down Expand Up @@ -131,7 +133,8 @@ fun VideoPlayerSeekBarPreview() {
VideoPlayerSeekBar(
contentProgress = Duration.parse("7m 51s"),
contentDuration = Duration.parse("23m 40s"),
seekProgressStep = 30.seconds,
seekBackIncrement = C.DEFAULT_SEEK_BACK_INCREMENT_MS.milliseconds,
seekForwardIncrement = C.DEFAULT_SEEK_FORWARD_INCREMENT_MS.milliseconds,
onSeek = {},
state = rememberVideoPlayerState(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.media3.common.C
import androidx.tv.material3.Icon
import androidx.tv.material3.IconButton
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.Text
import dev.jdtech.jellyfin.ui.theme.FindroidTheme
import dev.jdtech.jellyfin.ui.theme.spacings
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.Duration.Companion.milliseconds
import dev.jdtech.jellyfin.core.R as CoreR

@Composable
Expand All @@ -34,6 +35,8 @@ fun VideoPlayerSeeker(
onSeek: (Float) -> Unit,
contentProgress: Duration,
contentDuration: Duration,
seekBackIncrement: Duration,
seekForwardIncrement: Duration,
) {
val contentProgressString =
contentProgress.toComponents { h, m, s, _ ->
Expand Down Expand Up @@ -94,8 +97,8 @@ fun VideoPlayerSeeker(
VideoPlayerSeekBar(
contentProgress = contentProgress,
contentDuration = contentDuration,
// TODO: pass param from setting cache
seekProgressStep = 30.seconds,
seekBackIncrement = seekBackIncrement,
seekForwardIncrement = seekForwardIncrement,
onSeek = onSeek,
state = state,
)
Expand All @@ -115,6 +118,8 @@ private fun VideoPlayerSeekerPreview() {
onSeek = {},
contentProgress = Duration.parse("7m 51s"),
contentDuration = Duration.parse("23m 40s"),
seekBackIncrement = C.DEFAULT_SEEK_BACK_INCREMENT_MS.milliseconds,
seekForwardIncrement = C.DEFAULT_SEEK_FORWARD_INCREMENT_MS.milliseconds,
)
}
}
Expand Down

0 comments on commit b4e5a08

Please sign in to comment.