Fix/volume unmute to original value - #2274
Conversation
Previously, muting and unmuting would put the slider at max volume regardless of what the previous value was. Add logic to remember this previous value so when unmuting, the volume returns to what it was beforehand.
Previously, muting and unmuting would put the slider at max volume regardless of what the previous value was. Add logic to remember this previous value so when unmuting, the volume returns to what it was beforehand.
…lue' into fix/volume-unmute-to-original-value # Conflicts: # composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/ui/screen/MiniPlayer.kt
There was a problem hiding this comment.
Pull request overview
This PR updates the MiniPlayer mute/unmute behavior so unmuting restores the previous non-zero volume instead of jumping to max, improving volume UX in the Compose Multiplatform UI. (PR này cập nhật hành vi tắt/bật tiếng của MiniPlayer để khi bật tiếng lại sẽ khôi phục âm lượng khác 0 trước đó thay vì nhảy lên tối đa, cải thiện trải nghiệm âm lượng trong UI Compose Multiplatform.)
Changes: (Các thay đổi:)
- Track the last non-zero volume in composable state and use it when unmuting. (Theo dõi âm lượng khác 0 gần nhất trong state của composable và dùng nó khi bật tiếng lại.)
- Apply a 10% minimum volume floor when restoring volume from mute. (Áp dụng ngưỡng âm lượng tối thiểu 10% khi khôi phục từ trạng thái tắt tiếng.)
Comments suppressed due to low confidence (1)
composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/ui/screen/MiniPlayer.kt:859
- When unmuting,
previousVolumeValue.coerceAtLeast(0.1f)enforces the minimum but doesn't cap the upper bound. UsingcoerceIn(0.1f, 1f)makes the value safe even ifpreviousVolumeValueever becomes out of range (e.g., via a future state/restore bug).
sharedViewModel.onUIEvent(UIEvent.UpdateVolume(previousVolumeValue.coerceAtLeast(0.1f)))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/ui/screen/MiniPlayer.kt:898
- Follow-up: update the slider handler to use the renamed
lastNonZeroVolumestate so the file compiles after the rename.
onValueChange = {
isVolumeSliding = true
volumeValue = it
if (it > 0f) previousVolumeValue = it
},
composeApp/src/commonMain/kotlin/com/maxrave/simpmusic/ui/screen/MiniPlayer.kt:860
- The new state tracks the last non-zero volume used for restoring after unmute, so the name
previousVolumeValueis misleading (it sounds like the previous recomposition value), and the0.1fthreshold is repeated inline. Renaming to something likelastNonZeroVolumeand extracting aminUnmuteVolumeconstant makes the intent clearer and reduces magic numbers.
This issue also appears on line 894 of the same file.
var previousVolumeValue by rememberSaveable {
mutableFloatStateOf(controllerState.volume.coerceAtLeast(0.1f))
}
LaunchedEffect(controllerState.volume) {
if (controllerState.volume > 0f) {
previousVolumeValue = controllerState.volume
}
}
IconButton(
onClick = {
// Toggle mute/unmute
if (controllerState.volume > 0f) {
previousVolumeValue = controllerState.volume
sharedViewModel.onUIEvent(UIEvent.UpdateVolume(0f))
} else {
sharedViewModel.onUIEvent(UIEvent.UpdateVolume(previousVolumeValue.coerceIn(0.1f, 1f)))
}
Hi,
I noticed that when I click the mute button and unmute it, the volume slider goes to the max. I think it's nicer to have the volume return to the previous value it had so I implemented that change. I set a threshold of a 10% minimum when unmuting.
Old Version
https://github.com/user-attachments/assets/1e434a87-f230-4b97-b4c4-d9eb4c3de793
New Version
https://github.com/user-attachments/assets/f18be11b-4f31-4fc4-ad7a-2f42805da88c