add more logic to the audio player

This commit is contained in:
Christian Schabesberger 2024-09-22 14:57:23 +02:00
parent ea0f20a578
commit 72d6874880
5 changed files with 65 additions and 45 deletions

View File

@ -141,7 +141,10 @@ fun NewPlayerUI(
uiState.uiMode == UIModeState.EMBEDDED_VIDEO_CHAPTER_SELECT
) {
VideoPlayerUi(viewModel = viewModel, uiState = uiState)
} else if (uiState.uiMode == UIModeState.FULLSCREEN_AUDIO) {
} else if (uiState.uiMode == UIModeState.FULLSCREEN_AUDIO ||
uiState.uiMode == UIModeState.AUDIO_STREAM_SELECT ||
uiState.uiMode == UIModeState.AUDIO_CHAPTER_SELECT
) {
AudioPlayerUI(viewModel = viewModel, uiState = uiState)
} else {
LoadingPlaceholder(uiState.embeddedUiRatio)

View File

@ -59,30 +59,27 @@ import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
@OptIn(UnstableApi::class)
@Composable
fun AudioPlaybackController(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState) {
Row(modifier = Modifier.background(MaterialTheme.colorScheme.background),
verticalAlignment = Alignment.CenterVertically) {
Row(
modifier = Modifier.background(MaterialTheme.colorScheme.background),
verticalAlignment = Alignment.CenterVertically
) {
ShuffleModeButton(viewModel = viewModel, uiState = uiState)
Box(modifier = Modifier.size(80.dp), contentAlignment = Alignment.Center) {
androidx.compose.animation.AnimatedVisibility(
uiState.currentPlaylistItemIndex != 0,
enter = fadeIn(animationSpec = tween(400)),
exit = fadeOut(animationSpec = tween(400))
Button(
modifier = Modifier
.fillMaxSize()
.aspectRatio(1f),
onClick = viewModel::prevStream,
colors = lightAudioControlButtonColorScheme(),
enabled =
uiState.currentPlaylistItemIndex != 0
) {
Button(
modifier = Modifier
.fillMaxSize()
.aspectRatio(1f),
onClick = {},
colors = lightAudioControlButtonColorScheme()
) {
Icon(
modifier = Modifier.fillMaxSize(),
imageVector = Icons.Filled.SkipPrevious,
contentDescription = stringResource(R.string.widget_description_previous_stream)
)
}
Icon(
modifier = Modifier.fillMaxSize(),
imageVector = Icons.Filled.SkipPrevious,
contentDescription = stringResource(R.string.widget_description_previous_stream)
)
}
}
@ -92,6 +89,7 @@ fun AudioPlaybackController(viewModel: NewPlayerViewModel, uiState: NewPlayerUIS
shape = CircleShape
) {
Icon(
modifier = Modifier.fillMaxSize(),
imageVector = if (uiState.playing) Icons.Filled.Pause else Icons.Filled.PlayArrow,
contentDescription = stringResource(
if (uiState.playing) R.string.widget_description_pause
@ -101,24 +99,19 @@ fun AudioPlaybackController(viewModel: NewPlayerViewModel, uiState: NewPlayerUIS
}
Box(modifier = Modifier.size(80.dp), contentAlignment = Alignment.Center) {
androidx.compose.animation.AnimatedVisibility(
uiState.currentPlaylistItemIndex < uiState.playList.size - 1,
enter = fadeIn(animationSpec = tween(400)),
exit = fadeOut(animationSpec = tween(400))
Button(
modifier = Modifier
.fillMaxSize()
.aspectRatio(1f),
onClick = viewModel::nextStream,
colors = lightAudioControlButtonColorScheme(),
enabled = uiState.currentPlaylistItemIndex < uiState.playList.size - 1
) {
Button(
modifier = Modifier
.fillMaxSize()
.aspectRatio(1f),
onClick = {},
colors = lightAudioControlButtonColorScheme()
) {
Icon(
modifier = Modifier.fillMaxSize(),
imageVector = Icons.Filled.SkipNext,
contentDescription = stringResource(R.string.widget_description_next_stream)
)
}
Icon(
modifier = Modifier.fillMaxSize(),
imageVector = Icons.Filled.SkipNext,
contentDescription = stringResource(R.string.widget_description_next_stream)
)
}
}
@ -134,7 +127,7 @@ fun AudioPlayerControllerPreview() {
VideoPlayerTheme {
AudioPlaybackController(
viewModel = NewPlayerViewModelDummy(),
uiState = NewPlayerUIState.DUMMY
uiState = NewPlayerUIState.DUMMY.copy(playList = emptyList())
)
}
}

View File

@ -57,7 +57,8 @@ import net.newpipe.newplayer.utils.getInsets
@Composable
fun lightAudioControlButtonColorScheme() = ButtonDefaults.buttonColors().copy(
containerColor = MaterialTheme.colorScheme.background,
contentColor = MaterialTheme.colorScheme.onSurface
contentColor = MaterialTheme.colorScheme.onSurface,
disabledContainerColor = MaterialTheme.colorScheme.background
)
@OptIn(UnstableApi::class)

View File

@ -22,6 +22,7 @@
package net.newpipe.newplayer.ui.audioplayer
import android.app.Activity
import androidx.annotation.OptIn
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@ -55,19 +56,28 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.R
import net.newpipe.newplayer.model.EmbeddedUiConfig
import net.newpipe.newplayer.model.NewPlayerUIState
import net.newpipe.newplayer.model.NewPlayerViewModel
import net.newpipe.newplayer.model.NewPlayerViewModelDummy
import net.newpipe.newplayer.model.UIModeState
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.utils.getEmbeddedUiConfig
@OptIn(UnstableApi::class)
@Composable
fun AudioBottomUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState) {
val embeddedUiConfig = if(LocalContext.current is Activity)
getEmbeddedUiConfig(activity = LocalContext.current as Activity)
else
EmbeddedUiConfig.DUMMY
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Row(
modifier = Modifier
@ -75,7 +85,9 @@ fun AudioBottomUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState) {
.weight(1f), horizontalArrangement = Arrangement.SpaceAround
) {
Button(
onClick = { /*TODO*/ },
onClick = {
viewModel.changeUiMode(UIModeState.EMBEDDED_AUDIO, embeddedUiConfig)
},
colors = lightAudioControlButtonColorScheme()
) {
Icon(
@ -85,7 +97,9 @@ fun AudioBottomUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState) {
)
)
}
Button(onClick = { /*TODO*/ }, colors = lightAudioControlButtonColorScheme()) {
Button(onClick = {
viewModel.changeUiMode(UIModeState.FULLSCREEN_VIDEO, embeddedUiConfig)
}, colors = lightAudioControlButtonColorScheme()) {
Icon(
imageVector = Icons.Filled.LiveTv,
contentDescription = stringResource(
@ -93,7 +107,9 @@ fun AudioBottomUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState) {
)
)
}
Button(onClick = { /*TODO*/ }, colors = lightAudioControlButtonColorScheme()) {
Button(onClick = {
viewModel.changeUiMode(UIModeState.AUDIO_CHAPTER_SELECT, embeddedUiConfig)
}, colors = lightAudioControlButtonColorScheme()) {
Icon(
imageVector = Icons.AutoMirrored.Filled.MenuBook,
contentDescription = stringResource(
@ -101,7 +117,9 @@ fun AudioBottomUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState) {
)
)
}
Button(onClick = { /*TODO*/ }, colors = lightAudioControlButtonColorScheme()) {
Button(onClick = {
viewModel.changeUiMode(UIModeState.AUDIO_STREAM_SELECT, embeddedUiConfig)
}, colors = lightAudioControlButtonColorScheme()) {
Icon(
imageVector = Icons.AutoMirrored.Filled.List,
contentDescription = stringResource(
@ -118,6 +136,11 @@ fun AudioBottomUI(viewModel: NewPlayerViewModel, uiState: NewPlayerUIState) {
private fun Menu() {
var showMenu: Boolean by remember { mutableStateOf(false) }
val embeddedUiConfig = if(LocalContext.current is Activity)
getEmbeddedUiConfig(activity = LocalContext.current as Activity)
else
EmbeddedUiConfig.DUMMY
Box {
IconButton(onClick = {
showMenu = true

View File

@ -56,5 +56,5 @@
<string name="stream_thumbnail">Stream Thumbnail</string>
<string name="details_view_button_description">Switch to details view</string>
<string name="fullscreen_button_description">Switch to fullscreen video mode</string>
<string name="pip_button_description">Switch to picture in picture mode</string>
<string name="pip_button_description">Picture in picture</string>
</resources>