Skip to content

[Feature] Add option to duck music player volume instead of pausing (#541)#862

Open
LoackyBit wants to merge 4 commits into
kyleneideck:masterfrom
LoackyBit:feature/audio/auto-ducking
Open

[Feature] Add option to duck music player volume instead of pausing (#541)#862
LoackyBit wants to merge 4 commits into
kyleneideck:masterfrom
LoackyBit:feature/audio/auto-ducking

Conversation

@LoackyBit

@LoackyBit LoackyBit commented Jun 26, 2026

Copy link
Copy Markdown

Description

This PR implements the auto-ducking feature requested in issue #541. When enabled, instead of pausing the selected music player when other audio starts, Background Music will temporarily duck the music player's volume, restoring it when silence returns.

Key Changes

  • Auto-duck Toggle: Added a checkable "Duck instead of pause" menu item under the Auto-pause [Selected Player] Preferences submenu. When active, the main menu title dynamically changes from "Auto-pause [Selected Player]" to "Auto-duck [Selected Player]".
  • Ducking Volume Slider: Added a dynamic NSSlider for Ducking Volume in the Preferences submenu to allow users to set the ducking volume level (0% to 100%, defaults to 30%).
  • Reactive UI: The Ducking Volume slider dynamically enables/disables depending on whether the auto-duck option is checked. Slider adjustments update currently-ducked player volumes in real time.
  • Audio State Transitions & Fixes:
    • Since ducked music players continue playing audio, the device's audible state transitions to kBGMDeviceIsSilentExceptMusic instead of kBGMDeviceIsSilent when other audio stops. The listener block now correctly handles this state to trigger the unducking process.
    • Initialized and defaulted fallback volumes to 50 (the neutral midpoint raw volume in the driver curve). This fixes an issue where a 50% ducking level resulted in a no-op, and prevents unducking from boosting the player volume to 100 (400% volume boost).
    • Added a tolerance range ($\pm 1$) when comparing the current volume to the target ducked volume to account for float-to-int rounding differences by CoreAudio.

Type of Change

  • New feature

Related Issues

Closes #541

How to Test

  1. Launch Background Music and navigate to Preferences -> Auto-pause [Selected Player].
  2. Select your music player of choice.
  3. Check the Duck instead of pause option and verify that the main menu label updates to Auto-duck [Selected Player].
  4. Play music on the selected player, then play audio from another app (e.g. YouTube in Chrome).
  5. Verify that the player's volume ducks to the level specified by the new Ducking Volume slider.
  6. Verify that changing the Ducking Volume slider while the music is ducked updates its volume in real time.
  7. Stop the other app's audio and verify that the player's volume is restored to its exact pre-ducked volume.
  8. Manually adjust the player's volume while ducked. Stop the other audio and verify that the manual adjustment is preserved as the new baseline volume.

…ausing (kyleneideck#541)

Add support for auto-ducking the selected music player app's volume to 30%
when other applications play audio, rather than pausing it.

Closes kyleneideck#541
…der (kyleneideck#541)

- Fix issue where volume is not restored after ducking by correctly checking
  for kBGMDeviceIsSilentExceptMusic state in the listener block and unpause queue.
- Add a custom NSSlider to BGMPreferencesMenu to allow users to adjust the ducking
  volume percentage dynamically (defaulting to 30%).
- Ensure the slider is enabled/disabled reactively depending on the "Duck instead
  of pause" state.
- Update tests and user defaults database structure.

Closes kyleneideck#541
…kyleneideck#541)

Setting the fallback volume to 50 (the neutral midpoint) solves two issues:
1. Prevents ducking from failing (being a no-op) when set to exactly 50%.
2. Prevents the restored volume from jumping to 100% (boosted) upon unducking.
@LoackyBit

Copy link
Copy Markdown
Author

@kyleneideck can you review and merge the PR?

Comment thread BGMApp/BGMApp/BGMAutoPauseMusic.mm
Comment thread BGMApp/BGMApp/BGMAutoPauseMusic.mm
Comment thread BGMApp/BGMApp/BGMAutoPauseMusic.mm Outdated
@kyleneideck

Copy link
Copy Markdown
Owner

Hi @LoackyBit , thanks for the PR. I'm going to try to go through the PR backlog in order. I've been testing #853 and made some changes on top of it, but I think it's pretty close. So I'm not sure how long until I get to this one, but hopefully fairly soon.

I had a quick look through and left a few minor comments, but overall it looks good so far.

@LoackyBit

Copy link
Copy Markdown
Author

Thanks for the review and the feedback @kyleneideck. I’ve already pushed a new commit implementing your suggestions. No rush on the merge, just let me know if you spot anything else I should improve.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto ducking music player instead of pausing

2 participants