Skip to content

Fix/volume unmute to original value - #2274

Open
laoluogun wants to merge 6 commits into
maxrave-dev:devfrom
laoluogun:fix/volume-unmute-to-original-value
Open

Fix/volume unmute to original value#2274
laoluogun wants to merge 6 commits into
maxrave-dev:devfrom
laoluogun:fix/volume-unmute-to-original-value

Conversation

@laoluogun

Copy link
Copy Markdown
Contributor

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

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. Using coerceIn(0.1f, 1f) makes the value safe even if previousVolumeValue ever 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.

laoluogun and others added 2 commits July 25, 2026 09:22
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@maxrave-dev
maxrave-dev requested a review from Copilot July 28, 2026 11:39
@maxrave-dev maxrave-dev added this to the v1.7.0 milestone Jul 28, 2026
@github-project-automation github-project-automation Bot moved this to To triage in SimpMusic Jul 28, 2026
@maxrave-dev maxrave-dev moved this from To triage to In review in SimpMusic Jul 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 lastNonZeroVolume state 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 previousVolumeValue is misleading (it sounds like the previous recomposition value), and the 0.1f threshold is repeated inline. Renaming to something like lastNonZeroVolume and extracting a minUnmuteVolume constant 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)))
                                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants