make embedded audio player fit in its place

This commit is contained in:
Christian Schabesberger 2024-09-25 12:31:56 +02:00
parent 40b0ee5c6f
commit f544d8bc76
3 changed files with 34 additions and 13 deletions

View File

@ -70,7 +70,7 @@ fun AudioPlayerEmbeddedUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUISta
else
EmbeddedUiConfig.DUMMY
Box(modifier = Modifier.fillMaxSize()) {
Box(modifier = Modifier.wrapContentSize()) {
Thumbnail(
modifier = Modifier.fillMaxWidth(),
thumbnail = uiState.currentlyPlaying?.mediaMetadata?.artworkUri,
@ -139,18 +139,25 @@ fun AudioPlayerEmbeddedUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUISta
.align(Alignment.BottomStart)
.fillMaxWidth(),
progress = {
uiState.playbackPositionInMs.toFloat() / uiState.durationInMs.toFloat()
val duration = if (uiState.durationInMs == 0L) {
0.000000001f
} else {
uiState.durationInMs.toFloat()
}
(uiState.playbackPositionInMs.toFloat() / duration)
})
Surface(modifier = Modifier
.fillMaxSize()
.clickable {
viewModel.changeUiMode(
UIModeState.FULLSCREEN_AUDIO,
embeddedUiConfig = embeddedUIConfig
)
}, color = Color.Transparent
Surface(
modifier = Modifier
.matchParentSize()
.clickable {
viewModel.changeUiMode(
UIModeState.FULLSCREEN_AUDIO,
embeddedUiConfig = embeddedUIConfig
)
}, color = Color.Transparent
) {
}
@ -158,7 +165,7 @@ fun AudioPlayerEmbeddedUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUISta
}
@OptIn(UnstableApi::class)
@Preview(device = "spec:width=1080px,height=600px,dpi=440,orientation=landscape")
@Preview(device = "spec:width=1080px,height=1080px,dpi=440,orientation=landscape")
@Composable
fun AuidioPlayerEmbeddedPreview() {
VideoPlayerTheme {

View File

@ -38,6 +38,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
@ -88,7 +89,7 @@ fun AudioPlayerUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState, isLa
Box(
modifier = Modifier
.fillMaxSize()
.wrapContentSize()
.background(color = MaterialTheme.colorScheme.background)
) {
AnimatedVisibility(
@ -364,3 +365,16 @@ fun AudioPlayerUILandscapePreview() {
)
}
}
@OptIn(UnstableApi::class)
@Preview(device = "spec:parent=pixel_6,orientation=portrait", showSystemUi = true)
@Composable
fun AudioPlayerUIEmbeddedPreview() {
VideoPlayerTheme {
AudioPlayerUI(
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DUMMY.copy(uiMode = UIModeState.EMBEDDED_AUDIO),
isLandScape = false
)
}
}

View File

@ -110,7 +110,7 @@ fun AudioPlayerUIColorPreview() {
AudioPlayerUI(
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DUMMY.copy(
uiMode = UIModeState.EMBEDDED_VIDEO_CONTROLLER_UI,
uiMode = UIModeState.FULLSCREEN_AUDIO,
playing = true,
seekerPosition = 0.3f,
isLoading = false,