Skip to content

Add min and max volume functionality per player#3360

Open
OzGav wants to merge 20 commits intodevfrom
min-max-volume
Open

Add min and max volume functionality per player#3360
OzGav wants to merge 20 commits intodevfrom
min-max-volume

Conversation

@OzGav
Copy link
Copy Markdown
Contributor

@OzGav OzGav commented Mar 12, 2026

FRONTEND CHANGES: music-assistant/frontend#1569
Satisifies: https://github.com/orgs/music-assistant/discussions/3288

Add configurable min/max volume limits per player

Summary

  • Adds per-player minimum and maximum volume configuration options (advanced settings under player controls)
  • Volume commands (volume_set, volume_up, volume_down) are scaled from the UI’s 0-100 range to the configured min-max range before being sent to the device
  • External volume changes (physical buttons, other apps) are reverse-scaled back to 0-100 for reporting, so the UI always displays a consistent 0-100 range
  • Group volume adjustments work correctly since scaling is applied per child player
  • Config validation rejects min > max to prevent invalid states
  • Works with all API clients (frontend, Home Assistant, third-party) without any client-side changes

Edge cases and functionality covered

cmd_volume_set — The 0-100 input is linearly mapped to [min_volume, max_volume] via min_volume + (volume_level * (max_volume - min_volume)) // 100 before reaching the device. Applies to all programmatic and API invocations.

cmd_volume_up / cmd_volume_down — Step-based changes still operate in the 0-100 UI range (step sizes of 1-3 depending on position). Scaling happens downstream in _handle_cmd_volume_set, so no special casing is needed here.

External volume changes — When a device reports a volume change (e.g. user pressed a physical volume button, or used a manufacturer app), signal_player_state_update reverse-scales the reported value back to the 0-100 range before it reaches the UI. This keeps the slider position consistent with user expectations regardless of how the volume was changed.

Group volume — Each child player is scaled independently using its own min_volume/max_volume, so a group volume of 80 translates correctly for each member (e.g. a soundbar with max=50 receives 40, a regular speaker with max=100 receives 80).

Config validation — on_player_config_change validates that min_volume <= max_volume and raises InvalidDataError if not.

Falsy value handling — Uses explicit is not None checks rather than truthiness when reading config values, so min_volume=0 (a valid and common default) isn’t incorrectly treated as missing.

Advanced settings — Both config entries are marked as advanced so they don’t clutter the basic player settings for users who don’t need them.

Default behavior unchanged — With defaults of min=0 and max=100, the scaling formula is the identity function, so all existing behavior is preserved.

@MarvinSchenkel MarvinSchenkel added this to the 2.9.0 milestone Mar 12, 2026
@oleost
Copy link
Copy Markdown

oleost commented Mar 13, 2026

Thanks for trying to fix https://github.com/orgs/music-assistant/discussions/3288

Was wondering, would it be possible to implement also a option to scale the volume ?

Something like this:
https://github.com/oleost/server/tree/dev-max-volum-scale

image image

@oleost
Copy link
Copy Markdown

oleost commented Mar 27, 2026

Readjusted the mentioned pull request above to only scale volume.

@marcelveldt
Copy link
Copy Markdown
Member

  1. Agreed on scaling the volume - that is imo the only way to implement this properly.
  2. Do we really need min volume ? Isn't this always about max volume ?

@oleost
Copy link
Copy Markdown

oleost commented Mar 30, 2026

  1. Agreed on scaling the volume - that is imo the only way to implement this properly.

    1. Do we really need min volume ? Isn't this always about max volume ?

For me personally I don't need min volume, however was someone that requested it, and cant see what it hurts implementing it at the same time. Mute still works.

@OzGav OzGav marked this pull request as draft April 11, 2026 22:22
@OzGav OzGav marked this pull request as ready for review April 13, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants