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()
.also {
it.addListener(MusicPlayerListener(it, _state))
it.prepare()
}
}
@ -85,7 +84,10 @@ class MusicService
}
}
}
onMain { player.play() }
onMain {
player.prepare()
player.play()
}
}
suspend fun stop() {

View file

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

View file

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

View file

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

View file

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