mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
When scrubbing show position's time even without preview images (#175)
When scrubbing along the seek bar, always show the position's time even if there is no trickplay/preview image to display.
This commit is contained in:
parent
7bdf7952c9
commit
762e8f287d
2 changed files with 77 additions and 80 deletions
|
|
@ -342,37 +342,50 @@ fun PlaybackOverlay(
|
||||||
(playerControls.currentPosition.toFloat() / playerControls.duration)
|
(playerControls.currentPosition.toFloat() / playerControls.duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trickplayInfo != null) {
|
|
||||||
AnimatedVisibility(
|
|
||||||
seekProgressPercent >= 0 && seekBarFocused,
|
|
||||||
) {
|
|
||||||
val tilesPerImage = trickplayInfo.tileWidth * trickplayInfo.tileHeight
|
|
||||||
val index =
|
|
||||||
(seekProgressMs / trickplayInfo.interval).toInt() / tilesPerImage
|
|
||||||
val imageUrl = trickplayUrlFor(index)
|
|
||||||
|
|
||||||
if (imageUrl != null) {
|
AnimatedVisibility(
|
||||||
Box(
|
seekProgressPercent >= 0 && seekBarFocused,
|
||||||
modifier =
|
) {
|
||||||
Modifier
|
Box(
|
||||||
.align(Alignment.Center)
|
modifier =
|
||||||
.fillMaxWidth(.95f),
|
Modifier
|
||||||
) {
|
.align(Alignment.Center)
|
||||||
SeekPreviewImage(
|
.fillMaxWidth(.95f),
|
||||||
modifier =
|
) {
|
||||||
Modifier
|
Column(
|
||||||
.align(Alignment.BottomStart)
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
.offsetByPercent(
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
xPercentage = seekProgressPercent.coerceIn(0f, 1f),
|
modifier =
|
||||||
).padding(bottom = controllerHeight - titleHeight - subtitleHeight),
|
Modifier
|
||||||
previewImageUrl = imageUrl,
|
.align(Alignment.BottomStart)
|
||||||
duration = playerControls.duration,
|
.offsetByPercent(
|
||||||
seekProgressMs = seekProgressMs,
|
xPercentage = seekProgressPercent.coerceIn(0f, 1f),
|
||||||
videoWidth = trickplayInfo.width,
|
).padding(bottom = controllerHeight - titleHeight - subtitleHeight),
|
||||||
videoHeight = trickplayInfo.height,
|
) {
|
||||||
trickPlayInfo = trickplayInfo,
|
if (trickplayInfo != null) {
|
||||||
)
|
val tilesPerImage = trickplayInfo.tileWidth * trickplayInfo.tileHeight
|
||||||
|
val index =
|
||||||
|
(seekProgressMs / trickplayInfo.interval).toInt() / tilesPerImage
|
||||||
|
val imageUrl = trickplayUrlFor(index)
|
||||||
|
|
||||||
|
if (imageUrl != null) {
|
||||||
|
SeekPreviewImage(
|
||||||
|
modifier =
|
||||||
|
Modifier,
|
||||||
|
previewImageUrl = imageUrl,
|
||||||
|
duration = playerControls.duration,
|
||||||
|
seekProgressMs = seekProgressMs,
|
||||||
|
videoWidth = trickplayInfo.width,
|
||||||
|
videoHeight = trickplayInfo.height,
|
||||||
|
trickPlayInfo = trickplayInfo,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Text(
|
||||||
|
text = (seekProgressMs / 1000L).seconds.toString(),
|
||||||
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,9 @@ package com.github.damontecres.wholphin.ui.playback
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
|
|
@ -17,7 +14,6 @@ import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.tv.material3.MaterialTheme
|
import androidx.tv.material3.MaterialTheme
|
||||||
import androidx.tv.material3.Text
|
|
||||||
import coil3.compose.AsyncImage
|
import coil3.compose.AsyncImage
|
||||||
import coil3.request.CachePolicy
|
import coil3.request.CachePolicy
|
||||||
import coil3.request.ImageRequest
|
import coil3.request.ImageRequest
|
||||||
|
|
@ -25,7 +21,6 @@ import coil3.request.transformations
|
||||||
import com.github.damontecres.wholphin.ui.CoilTrickplayTransformation
|
import com.github.damontecres.wholphin.ui.CoilTrickplayTransformation
|
||||||
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
|
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
|
||||||
import org.jellyfin.sdk.model.api.TrickplayInfo
|
import org.jellyfin.sdk.model.api.TrickplayInfo
|
||||||
import kotlin.time.Duration.Companion.seconds
|
|
||||||
|
|
||||||
fun Modifier.offsetByPercent(
|
fun Modifier.offsetByPercent(
|
||||||
xPercentage: Float,
|
xPercentage: Float,
|
||||||
|
|
@ -85,55 +80,44 @@ fun SeekPreviewImage(
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
Column(
|
if (previewImageUrl.isNotNullOrBlank() &&
|
||||||
modifier = modifier,
|
videoWidth != null &&
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
videoHeight != null
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
) {
|
) {
|
||||||
if (previewImageUrl.isNotNullOrBlank() &&
|
val height = 160.dp
|
||||||
videoWidth != null &&
|
val width = height * (videoWidth.toFloat() / videoHeight)
|
||||||
videoHeight != null
|
val heightPx = with(LocalDensity.current) { height.toPx().toInt() }
|
||||||
) {
|
val widthPx = with(LocalDensity.current) { width.toPx().toInt() }
|
||||||
val height = 160.dp
|
|
||||||
val width = height * (videoWidth.toFloat() / videoHeight)
|
|
||||||
val heightPx = with(LocalDensity.current) { height.toPx().toInt() }
|
|
||||||
val widthPx = with(LocalDensity.current) { width.toPx().toInt() }
|
|
||||||
|
|
||||||
val index = (seekProgressMs.toDouble() / trickPlayInfo.interval).toInt() // Which tile
|
val index = (seekProgressMs.toDouble() / trickPlayInfo.interval).toInt() // Which tile
|
||||||
val numberOfTitlesPerImage = trickPlayInfo.tileHeight * trickPlayInfo.tileWidth
|
val numberOfTitlesPerImage = trickPlayInfo.tileHeight * trickPlayInfo.tileWidth
|
||||||
val imageIndex = index % numberOfTitlesPerImage
|
val imageIndex = index % numberOfTitlesPerImage
|
||||||
|
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
modifier
|
||||||
.width(width)
|
.width(width)
|
||||||
.height(height)
|
.height(height)
|
||||||
.background(Color.Black)
|
.background(Color.Black)
|
||||||
.border(1.5.dp, color = MaterialTheme.colorScheme.border),
|
.border(1.5.dp, color = MaterialTheme.colorScheme.border),
|
||||||
model =
|
model =
|
||||||
ImageRequest
|
ImageRequest
|
||||||
.Builder(context)
|
.Builder(context)
|
||||||
.data(previewImageUrl)
|
.data(previewImageUrl)
|
||||||
.memoryCachePolicy(CachePolicy.ENABLED)
|
.memoryCachePolicy(CachePolicy.ENABLED)
|
||||||
.transformations(
|
.transformations(
|
||||||
CoilTrickplayTransformation(
|
CoilTrickplayTransformation(
|
||||||
widthPx,
|
widthPx,
|
||||||
heightPx,
|
heightPx,
|
||||||
trickPlayInfo.tileHeight,
|
trickPlayInfo.tileHeight,
|
||||||
trickPlayInfo.tileWidth,
|
trickPlayInfo.tileWidth,
|
||||||
imageIndex,
|
imageIndex,
|
||||||
index,
|
index,
|
||||||
),
|
),
|
||||||
).build(),
|
).build(),
|
||||||
contentScale = ContentScale.None,
|
contentScale = ContentScale.None,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
placeholder = placeHolder,
|
placeholder = placeHolder,
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
text = (seekProgressMs / 1000L).seconds.toString(),
|
|
||||||
color = MaterialTheme.colorScheme.onSurface,
|
|
||||||
style = MaterialTheme.typography.labelLarge,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue