youpipe: add tempo/pitch controls and fullscreen lock-controls button to the player
- Commit
c6c0eeb552760d64f504ee32738da85a91893c72- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-08 17:39 UTC (4 months ago)
- Parents
4c699ac
Diff
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.ktindex 18904cd1f8..887c0ae087 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt@@ -27,19 +27,24 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import com.vayunmathur.library.ui.DropdownMenu import com.vayunmathur.library.ui.DropdownMenuItem+import com.vayunmathur.library.ui.Checkbox+import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.IconArrowDropDown import com.vayunmathur.library.ui.IconFullscreen import com.vayunmathur.library.ui.IconFullscreenExit import com.vayunmathur.library.ui.IconList+import com.vayunmathur.library.ui.IconLock import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Slider import com.vayunmathur.library.ui.SliderDefaults import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect@@ -65,6 +70,7 @@ import androidx.media3.common.C import androidx.media3.common.MediaItem import androidx.media3.common.MediaMetadata import androidx.media3.common.MimeTypes+import androidx.media3.common.PlaybackParameters import androidx.media3.common.Player import androidx.media3.common.VideoSize import androidx.media3.common.text.Cue@@ -158,6 +164,17 @@ fun VideoPlayer( var isLanguageMenuExpanded by remember { mutableStateOf(false) } var isChapterMenuVisible by remember { mutableStateOf(false) } var isCaptionMenuExpanded by remember { mutableStateOf(false) }+ var isSpeedMenuExpanded by remember { mutableStateOf(false) }++ // Tempo (playback speed) and pitch, applied via PlaybackParameters. When pitch is "hooked"+ // to tempo it tracks it 1:1 (natural resample); unhooking lets the user set it independently.+ var playbackSpeed by remember { mutableFloatStateOf(1f) }+ var playbackPitch by remember { mutableFloatStateOf(1f) }+ var unhookPitch by remember { mutableStateOf(false) }++ // Lock hides all controls (and disables seek/speed gestures) so a fullscreen video can't be+ // disturbed by accidental touches, until the user taps the on-screen unlock button.+ var isLocked by remember { mutableStateOf(false) } var selectedSubtitle by remember { mutableStateOf<SubtitleTrack?>(null) } var cues by remember { mutableStateOf<List<Cue>>(emptyList()) }@@ -380,6 +397,11 @@ fun VideoPlayer( }.build() } + // Apply tempo/pitch whenever they change (or the controller connects).+ LaunchedEffect(controller, playbackSpeed, playbackPitch) {+ controller?.playbackParameters = PlaybackParameters(playbackSpeed, playbackPitch)+ }+ val isPipMode = rememberIsInPipMode() val scope = rememberCoroutineScope() @@ -392,6 +414,7 @@ fun VideoPlayer( detectTapGestures( onTap = { isControlsVisible = !isControlsVisible }, onDoubleTap = { offset ->+ if (isLocked) return@detectTapGestures val isRightSide = offset.x > size.width / 2 if (isRightSide) { controller?.seekTo(currentPosition + 10000L)@@ -400,6 +423,7 @@ fun VideoPlayer( } }, onPress = {+ if (isLocked) return@detectTapGestures val job = scope.launch { delay(viewConfiguration.longPressTimeoutMillis) controller?.setPlaybackSpeed(2f)@@ -408,7 +432,8 @@ fun VideoPlayer( awaitRelease() } finally { job.cancel()- controller?.setPlaybackSpeed(1f)+ // Restore the user's chosen tempo/pitch, not a hardcoded 1x.+ controller?.playbackParameters = PlaybackParameters(playbackSpeed, playbackPitch) } } )@@ -450,7 +475,7 @@ fun VideoPlayer( } } - AnimatedVisibility(visible = isControlsVisible && !isPipMode, enter = fadeIn(), exit = fadeOut()) {+ AnimatedVisibility(visible = isControlsVisible && !isPipMode && !isLocked, enter = fadeIn(), exit = fadeOut()) { Box(modifier = Modifier.fillMaxSize().background(Color.Black.copy(alpha = 0.4f))) { Row(@@ -542,6 +567,90 @@ fun VideoPlayer( IconList(tint = Color.White, modifier = Modifier.size(20.dp)) } }++ Box {+ Surface(+ onClick = { isSpeedMenuExpanded = true },+ color = Color.Black.copy(alpha = 0.5f),+ shape = RoundedCornerShape(4.dp)+ ) {+ Row(modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), verticalAlignment = Alignment.CenterVertically) {+ Text(+ text = stringResource(R.string.playback_tempo_value, formatTempo(playbackSpeed)),+ color = Color.White,+ style = MaterialTheme.typography.labelMedium+ )+ IconArrowDropDown(tint = Color.White)+ }+ }+ DropdownMenu(expanded = isSpeedMenuExpanded, onDismissRequest = { isSpeedMenuExpanded = false }) {+ Column(modifier = Modifier.width(280.dp).padding(horizontal = 16.dp, vertical = 8.dp)) {+ Row(+ modifier = Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.SpaceBetween,+ verticalAlignment = Alignment.CenterVertically+ ) {+ Text(text = stringResource(R.string.playback_tempo), style = MaterialTheme.typography.titleSmall)+ Text(+ text = stringResource(R.string.playback_tempo_value, formatTempo(playbackSpeed)),+ style = MaterialTheme.typography.labelLarge+ )+ }+ Slider(+ value = playbackSpeed,+ onValueChange = {+ playbackSpeed = it+ if (!unhookPitch) playbackPitch = it+ },+ valueRange = 0.25f..2f,+ )+ Row(+ modifier = Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.SpaceBetween,+ verticalAlignment = Alignment.CenterVertically+ ) {+ Text(text = stringResource(R.string.playback_pitch), style = MaterialTheme.typography.titleSmall)+ Text(+ text = stringResource(R.string.playback_pitch_value, (playbackPitch * 100).toInt()),+ style = MaterialTheme.typography.labelLarge+ )+ }+ Slider(+ value = playbackPitch,+ onValueChange = { playbackPitch = it },+ valueRange = 0.5f..2f,+ enabled = unhookPitch,+ )+ Row(+ modifier = Modifier+ .fillMaxWidth()+ .clickable {+ unhookPitch = !unhookPitch+ if (!unhookPitch) playbackPitch = playbackSpeed+ },+ verticalAlignment = Alignment.CenterVertically+ ) {+ Checkbox(+ checked = unhookPitch,+ onCheckedChange = {+ unhookPitch = it+ if (!it) playbackPitch = playbackSpeed+ },+ )+ Text(text = stringResource(R.string.playback_unhook_pitch), style = MaterialTheme.typography.bodyMedium)+ }+ HorizontalDivider()+ TextButton(+ onClick = {+ playbackSpeed = 1f+ playbackPitch = 1f+ unhookPitch = false+ },+ modifier = Modifier.align(Alignment.End)+ ) { Text(stringResource(R.string.playback_reset)) }+ }+ }+ } } controller?.let { player ->@@ -614,6 +723,14 @@ fun VideoPlayer( } } Spacer(Modifier.padding(4.dp))+ if (isFullscreen) {+ IconButton(onClick = {+ isLocked = true+ isControlsVisible = false+ }) {+ IconLock(tint = Color.White)+ }+ } IconButton({onFullscreenChange(!isFullscreen)}) { if(isFullscreen) IconFullscreenExit() else IconFullscreen() }@@ -621,6 +738,23 @@ fun VideoPlayer( } } + AnimatedVisibility(visible = isLocked && isControlsVisible && !isPipMode, enter = fadeIn(), exit = fadeOut()) {+ Box(modifier = Modifier.fillMaxSize()) {+ IconButton(+ onClick = {+ isLocked = false+ isControlsVisible = true+ },+ modifier = Modifier+ .align(Alignment.Center)+ .background(Color.Black.copy(alpha = 0.5f), CircleShape)+ .size(56.dp)+ ) {+ IconLock(tint = Color.White, modifier = Modifier.size(28.dp))+ }+ }+ }+ AnimatedVisibility(visible = isChapterMenuVisible && !isPipMode, enter = fadeIn(), exit = fadeOut()) { Box(modifier = Modifier.fillMaxSize().background(Color.Black.copy(alpha = 0.9f)).clickable(enabled = true, onClick = {})) { Column(modifier = Modifier.fillMaxSize()) {@@ -675,3 +809,10 @@ fun VideoPlayer( } private const val HISTORY_UPSERT_INTERVAL_MS = 5000L++/** Formats a tempo multiplier for display: whole values as "2", fractional as "1.5". */+private fun formatTempo(speed: Float): String {+ val rounded = Math.round(speed * 100f) / 100f+ return if (rounded % 1f == 0f) rounded.toInt().toString()+ else rounded.toString().trimEnd('0').trimEnd('.')+}
youpipe/src/main/res/values/strings.xml
diff --git a/youpipe/src/main/res/values/strings.xml b/youpipe/src/main/res/values/strings.xmlindex 2e13d42851..ebc9f70b1d 100644--- a/youpipe/src/main/res/values/strings.xml+++ b/youpipe/src/main/res/values/strings.xml@@ -265,4 +265,21 @@ <string name="settings_sponsorblock_summary">%1$d of %2$d blocked</string> <!-- Recommendation preset name when the user has manually adjusted the dials. Adjective --> <string name="preset_custom">Custom</string>++ <!-- Player controls: title of the playback tempo (speed) slider. Noun -->+ <string name="playback_tempo">Tempo</string>+ <!-- Player controls: title of the playback pitch slider. Noun -->+ <string name="playback_pitch">Pitch</string>+ <!-- Player controls: tempo value as a multiplier. %1$s = value e.g. 1.5. Keep the x suffix -->+ <string name="playback_tempo_value"><xliff:g id="value" example="1.5">%1$s</xliff:g>x</string>+ <!-- Player controls: pitch value as a percentage. %1$d = value e.g. 100. Keep the percent sign -->+ <string name="playback_pitch_value"><xliff:g id="value" example="100">%1$d</xliff:g>%%</string>+ <!-- Player controls: checkbox to control pitch independently of tempo (may distort audio). Phrase -->+ <string name="playback_unhook_pitch">Unhook pitch (may distort)</string>+ <!-- Player controls: button that resets tempo and pitch to default. Verb -->+ <string name="playback_reset">Reset</string>+ <!-- Player controls: content description for the lock-controls button shown in fullscreen. Verb phrase -->+ <string name="lock_controls">Lock controls</string>+ <!-- Player controls: content description for the unlock button shown while controls are locked. Verb phrase -->+ <string name="unlock_controls">Unlock controls</string> </resources>