Add stop button

This commit is contained in:
Damontecres 2026-03-04 09:25:43 -05:00
parent 3359c8ac32
commit d8a58a6d96
No known key found for this signature in database
5 changed files with 21 additions and 4 deletions

View file

@ -68,7 +68,6 @@ class MusicService
).build() ).build()
.also { .also {
it.addListener(MusicPlayerListener(it, _state)) it.addListener(MusicPlayerListener(it, _state))
it.prepare()
} }
} }
@ -85,7 +84,10 @@ class MusicService
} }
} }
} }
onMain { player.play() } onMain {
player.prepare()
player.play()
}
} }
suspend fun stop() { suspend fun stop() {

View file

@ -61,6 +61,7 @@ fun NowPlayingButtons(
controllerViewState: ControllerViewState, controllerViewState: ControllerViewState,
initialFocusRequester: FocusRequester, initialFocusRequester: FocusRequester,
onClickMore: () -> Unit, onClickMore: () -> Unit,
onClickStop: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val playPauseState = rememberPlayPauseButtonState(player) val playPauseState = rememberPlayPauseButtonState(player)
@ -87,6 +88,15 @@ fun NowPlayingButtons(
onControllerInteraction = onControllerInteraction, onControllerInteraction = onControllerInteraction,
modifier = Modifier, modifier = Modifier,
) )
PlaybackButton(
iconRes = R.drawable.baseline_stop_24,
onClick = {
onClickStop.invoke()
},
enabled = true,
onControllerInteraction = onControllerInteraction,
modifier = Modifier,
)
} }
PlaybackButtons( PlaybackButtons(
player = player, player = player,

View file

@ -72,6 +72,7 @@ fun NowPlayingOverlay(
onClickMore: () -> Unit, onClickMore: () -> Unit,
onMoveQueue: (Int, MoveDirection) -> Unit, onMoveQueue: (Int, MoveDirection) -> Unit,
onClickMoreItem: (Int, AudioItem) -> Unit, onClickMoreItem: (Int, AudioItem) -> Unit,
onClickStop: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
@ -131,6 +132,7 @@ fun NowPlayingOverlay(
controllerViewState = controllerViewState, controllerViewState = controllerViewState,
initialFocusRequester = focusRequester, initialFocusRequester = focusRequester,
onClickMore = onClickMore, onClickMore = onClickMore,
onClickStop = onClickStop,
modifier = modifier =
Modifier Modifier
.fillMaxWidth() .fillMaxWidth()

View file

@ -231,6 +231,7 @@ fun NowPlayingPage(
onClickSong = { index, _ -> viewModel.play(index) }, onClickSong = { index, _ -> viewModel.play(index) },
onClickMoreItem = { index, song -> showContextForItem.invoke(false, index, song) }, onClickMoreItem = { index, song -> showContextForItem.invoke(false, index, song) },
onLongClickSong = { index, song -> showContextForItem.invoke(true, index, song) }, onLongClickSong = { index, song -> showContextForItem.invoke(true, index, song) },
onClickStop = { viewModel.stop() },
modifier = modifier =
Modifier Modifier
.background(AppColors.TransparentBlack50) .background(AppColors.TransparentBlack50)

View file

@ -185,7 +185,9 @@ class NowPlayingViewModel
fun removeFromQueue(index: Int) = viewModelScope.launchDefault { musicService.removeFromQueue(index) } fun removeFromQueue(index: Int) = viewModelScope.launchDefault { musicService.removeFromQueue(index) }
fun stop() { fun stop() {
player.stop() viewModelScope.launchDefault {
navigationManager.goBack() musicService.stop()
navigationManager.goBack()
}
} }
} }