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 else
EmbeddedUiConfig.DUMMY EmbeddedUiConfig.DUMMY
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.wrapContentSize()) {
Thumbnail( Thumbnail(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
thumbnail = uiState.currentlyPlaying?.mediaMetadata?.artworkUri, thumbnail = uiState.currentlyPlaying?.mediaMetadata?.artworkUri,
@ -139,18 +139,25 @@ fun AudioPlayerEmbeddedUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUISta
.align(Alignment.BottomStart) .align(Alignment.BottomStart)
.fillMaxWidth(), .fillMaxWidth(),
progress = { 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 Surface(
.fillMaxSize() modifier = Modifier
.clickable { .matchParentSize()
viewModel.changeUiMode( .clickable {
UIModeState.FULLSCREEN_AUDIO, viewModel.changeUiMode(
embeddedUiConfig = embeddedUIConfig UIModeState.FULLSCREEN_AUDIO,
) embeddedUiConfig = embeddedUIConfig
}, color = Color.Transparent )
}, color = Color.Transparent
) { ) {
} }
@ -158,7 +165,7 @@ fun AudioPlayerEmbeddedUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUISta
} }
@OptIn(UnstableApi::class) @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 @Composable
fun AuidioPlayerEmbeddedPreview() { fun AuidioPlayerEmbeddedPreview() {
VideoPlayerTheme { VideoPlayerTheme {

View File

@ -38,6 +38,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults import androidx.compose.material3.CardDefaults
@ -88,7 +89,7 @@ fun AudioPlayerUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState, isLa
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .wrapContentSize()
.background(color = MaterialTheme.colorScheme.background) .background(color = MaterialTheme.colorScheme.background)
) { ) {
AnimatedVisibility( AnimatedVisibility(
@ -363,4 +364,17 @@ fun AudioPlayerUILandscapePreview() {
isLandScape = true isLandScape = true
) )
} }
}
@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( AudioPlayerUI(
viewModel = NewPlayerViewModelDummy(), viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DUMMY.copy( uiState = NewPlayerUIState.DUMMY.copy(
uiMode = UIModeState.EMBEDDED_VIDEO_CONTROLLER_UI, uiMode = UIModeState.FULLSCREEN_AUDIO,
playing = true, playing = true,
seekerPosition = 0.3f, seekerPosition = 0.3f,
isLoading = false, isLoading = false,