youpipe: fullscreen video playback
- Commit
28f87167900d4b5fb56e47e4149212a2fa250a43- Author
- Vayun <[email protected]>
- When
- 2026-01-31 22:36 UTC (10 months ago)
- Parents
c2b1465
Diff
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.ktindex dd82c17039..875b8fe44f 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt@@ -1,11 +1,15 @@ package com.vayunmathur.youpipe.ui +import android.annotation.SuppressLint+import android.app.Activity import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth@@ -39,11 +43,17 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip+import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.ColorPainter+import androidx.compose.ui.layout.Layout+import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import androidx.core.net.toUri+import androidx.core.view.WindowCompat+import androidx.core.view.WindowInsetsCompat+import androidx.core.view.WindowInsetsControllerCompat import androidx.navigation3.runtime.NavBackStack import coil.compose.AsyncImage import com.vayunmathur.library.util.DatabaseViewModel@@ -75,6 +85,37 @@ data class VideoStream(val url: String, val width: Int, val height: Int, val bit data class VideoData(val title: String, val views: Long, val duration: Long, val uploadDate: Instant, val thumbnailURL: String, val author: String, val authorURL: String, val authorThumbnail: String) data class Comment(val text: String, val author: String, val likes: Int, val dislikes: Int) +@Composable+fun RotatedComponent(+ rotation: Float = 90f,+ content: @Composable () -> Unit+) {+ Layout(+ content = content,+ modifier = Modifier.rotate(rotation)+ ) { measurables, constraints ->+ // 1. Swap the constraints: MaxWidth becomes MaxHeight and vice versa+ val swappedConstraints = constraints.copy(+ minWidth = constraints.minHeight,+ maxWidth = constraints.maxHeight,+ minHeight = constraints.minWidth,+ maxHeight = constraints.maxWidth+ )++ // 2. Measure the child with the flipped constraints+ val placeable = measurables.first().measure(swappedConstraints)++ // 3. Set the parent size to the FLIPPED dimensions of the child+ layout(placeable.height, placeable.width) {+ // 4. Place the child centered+ placeable.placeRelative(+ x = (placeable.height - placeable.width) / 2,+ y = (placeable.width - placeable.height) / 2+ )+ }+ }+}+ @Composable fun VideoPage(backStack: NavBackStack<Route>, viewModel: DatabaseViewModel, videoID: Long) { val url = videoIDtoURL(videoID)@@ -114,10 +155,57 @@ fun VideoPage(backStack: NavBackStack<Route>, viewModel: DatabaseViewModel, vide } } + var isFullscreen by remember { mutableStateOf(false) }++ val view = LocalView.current+ LaunchedEffect(isFullscreen) {+ val window = (view.context as Activity).window+ val controller = WindowCompat.getInsetsController(window, view)++ if (isFullscreen) {+ // Hide both status bar and navigation bar+ controller.hide(WindowInsetsCompat.Type.systemBars())+ // Make it so they only reappear with a swipe and don't resize the layout+ controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE+ } else {+ controller.show(WindowInsetsCompat.Type.systemBars())+ }+ }++ if(isFullscreen) {+ @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")+ Scaffold(contentWindowInsets = WindowInsets(0, 0, 0, 0)) { paddingValues ->+ Box(Modifier.fillMaxSize()) {+ RotatedComponent() {+ videoData?.let {+ VideoPlayer(+ viewModel,+ VideoInfo(+ it.title,+ videoID,+ it.duration,+ it.views,+ it.uploadDate,+ it.thumbnailURL,+ it.author+ ),+ videoStreams,+ audioStreams,+ segments,+ true,+ { isFullscreen = it })+ }+ }+ }+ }+ return+ }++ Scaffold() { paddingValues -> Column(Modifier.padding(paddingValues)) { videoData?.let {- VideoPlayer(viewModel, VideoInfo(it.title, videoID, it.duration, it.views, it.uploadDate, it.thumbnailURL, it.author), videoStreams.first(), audioStreams.first(), videoStreams, audioStreams, segments)+ VideoPlayer(viewModel, VideoInfo(it.title, videoID, it.duration, it.views, it.uploadDate, it.thumbnailURL, it.author), videoStreams, audioStreams, segments, false, { isFullscreen = it }) VideoDetails(backStack, it) }
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 2cf2372f66..f4f3788d3b 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt@@ -34,6 +34,7 @@ import androidx.media3.common.util.UnstableApi import androidx.media3.session.MediaController import androidx.media3.session.SessionToken import androidx.media3.ui.compose.PlayerSurface+import androidx.media3.ui.compose.SURFACE_TYPE_TEXTURE_VIEW import androidx.media3.ui.compose.material3.buttons.PlayPauseButton import coil.compose.AsyncImage import com.google.common.util.concurrent.MoreExecutors@@ -50,11 +51,11 @@ import kotlinx.coroutines.delay fun VideoPlayer( viewModel: DatabaseViewModel, videoInfo: VideoInfo,- initialVideoStream: VideoStream,- initialAudioStream: AudioStream, videoStreams: List<VideoStream>, audioStreams: List<AudioStream>, segments: List<VideoChapter>,+ isFullscreen: Boolean,+ onFullscreenChange: (Boolean) -> Unit, ) { val context = LocalContext.current @@ -63,7 +64,7 @@ fun VideoPlayer( val audioStreamOptions = audioStreams.filter { it.language == language } var controller by remember { mutableStateOf<MediaController?>(null) }- var currentVideoStream by remember { mutableStateOf(initialVideoStream) }+ var currentVideoStream by remember { mutableStateOf(videoStreams.first()) } var currentAudioStream by remember { mutableStateOf(audioStreamOptions.first()) } var isControlsVisible by remember { mutableStateOf(true) } var currentPosition by remember { mutableLongStateOf(0L) }@@ -162,10 +163,11 @@ fun VideoPlayer( val isPipMode = rememberIsInPipMode() + val modifier = if(isFullscreen) Modifier.fillMaxHeight() else Modifier.aspectRatio(16f / 9f)+ Box(- modifier = Modifier+ modifier = modifier .fillMaxWidth()- .aspectRatio(16f / 9f) .clickable( interactionSource = remember { MutableInteractionSource() }, indication = null@@ -182,6 +184,7 @@ fun VideoPlayer( PlayerSurface( player = player, modifier = playerModifier.align(Alignment.Center),+ surfaceType = SURFACE_TYPE_TEXTURE_VIEW ) } ?: Box(modifier = Modifier.fillMaxSize().background(Color.Black)) @@ -272,19 +275,40 @@ fun VideoPlayer( modifier = Modifier.size(64.dp).align(Alignment.Center), ) }-- Column(modifier = Modifier.align(Alignment.BottomCenter).padding(horizontal = 16.dp, vertical = 8.dp)) {- Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {- Text(text = formatTime(currentPosition), color = Color.White, style = MaterialTheme.typography.labelSmall)- Text(text = formatTime(duration), color = Color.White, style = MaterialTheme.typography.labelSmall)+ Row(Modifier.align(Alignment.BottomCenter).padding(horizontal = 16.dp, vertical = 8.dp), verticalAlignment = Alignment.Bottom) {+ Column(Modifier.weight(1f)) {+ Row(+ modifier = Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.SpaceBetween+ ) {+ Text(+ text = formatTime(currentPosition),+ color = Color.White,+ style = MaterialTheme.typography.labelSmall+ )+ Text(+ text = formatTime(duration),+ color = Color.White,+ style = MaterialTheme.typography.labelSmall+ )+ }+ Slider(+ value = if (duration > 0) currentPosition.toFloat() else 0f,+ onValueChange = { isDragging = true; currentPosition = it.toLong() },+ onValueChangeFinished = {+ controller?.seekTo(currentPosition); isDragging = false+ },+ valueRange = 0f..(duration.toFloat().coerceAtLeast(1f)),+ colors = SliderDefaults.colors(+ thumbColor = MaterialTheme.colorScheme.primary,+ activeTrackColor = MaterialTheme.colorScheme.primary+ )+ )+ }+ Spacer(Modifier.padding(4.dp))+ IconButton({onFullscreenChange(!isFullscreen)}) {+ Icon(if(isFullscreen) painterResource(R.drawable.outline_fullscreen_exit_24) else painterResource(R.drawable.outline_fullscreen_24), null) }- Slider(- value = if (duration > 0) currentPosition.toFloat() else 0f,- onValueChange = { isDragging = true; currentPosition = it.toLong() },- onValueChangeFinished = { controller?.seekTo(currentPosition); isDragging = false },- valueRange = 0f..(duration.toFloat().coerceAtLeast(1f)),- colors = SliderDefaults.colors(thumbColor = MaterialTheme.colorScheme.primary, activeTrackColor = MaterialTheme.colorScheme.primary)- ) } } }
youpipe/src/main/res/drawable/outline_fullscreen_24.xml
diff --git a/youpipe/src/main/res/drawable/outline_fullscreen_24.xml b/youpipe/src/main/res/drawable/outline_fullscreen_24.xmlnew file mode 100644index 0000000000..ad187b0a0f--- /dev/null+++ b/youpipe/src/main/res/drawable/outline_fullscreen_24.xml@@ -0,0 +1,5 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">+ + <path android:fillColor="@android:color/white" android:pathData="M120,840L120,640L200,640L200,760L320,760L320,840L120,840ZM640,840L640,760L760,760L760,640L840,640L840,840L640,840ZM120,320L120,120L320,120L320,200L200,200L200,320L120,320ZM760,320L760,200L640,200L640,120L840,120L840,320L760,320Z"/>+ +</vector>
youpipe/src/main/res/drawable/outline_fullscreen_exit_24.xml
diff --git a/youpipe/src/main/res/drawable/outline_fullscreen_exit_24.xml b/youpipe/src/main/res/drawable/outline_fullscreen_exit_24.xmlnew file mode 100644index 0000000000..c46a45af81--- /dev/null+++ b/youpipe/src/main/res/drawable/outline_fullscreen_exit_24.xml@@ -0,0 +1,5 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">+ + <path android:fillColor="@android:color/white" android:pathData="M240,840L240,720L120,720L120,640L320,640L320,840L240,840ZM640,840L640,640L840,640L840,720L720,720L720,840L640,840ZM120,320L120,240L240,240L240,120L320,120L320,320L120,320ZM640,320L640,120L720,120L720,240L840,240L840,320L640,320Z"/>+ +</vector>