Page 1 of 1

Mute audio when bluetooth headphones disconnect

Posted: 30 Jun 2022, 19:44
by akirofe
Hi guys,

I listen to online radio at work with my bluetooth headphones. When I go to toilet I don't remember to take my headphones off and the headphones' bluetooth disconnects with the computer and the radio switches to play on the computer's built-in speakers.

Could you please help me with a code to mute or stop the audio when bluetooth headphones disconnect?

Thank you very much guys!!

Re: Mute audio when bluetooth headphones disconnect

Posted: 01 Jul 2022, 02:17
by BoBo
You could use SetTimer, periodically checking for your BT device. Maybe this helps: viewtopic.php?p=411138#p411138 (that has been created by @malcev) :)

Old, but seems to be able detecting a change via the registry!? https://www.autohotkey.com/board/topic/70836-any-way-to-detect-bluetooth-device-status/ :think:

Re: Mute audio when bluetooth headphones disconnect

Posted: 01 Jul 2022, 06:09
by RussF
Are you running Windows 10? I don't have Win 11, so I can't be certain it behaves the same, but would assume it does.

My Win 10 maintains separate volume levels for each output device attached (speakers, headphones, bluetooth, etc.) You can verify this by clicking on the speaker icon in your system tray with your headphones disconnected to see the value, then connect them and see the difference.
image.png
image.png (37.96 KiB) Viewed 1449 times
image.png
image.png (38.09 KiB) Viewed 1449 times
Simply disconnect your headphones, play the radio app and adjust the volume of the speakers to at or near zero (at least to a level that won't bother your co-workers). Then, connect the headset and adjust the volume to your preference. There shouldn't be a need for any scripting - at least I don't need any on my system at work for the same reason.

Russ

Re: Mute audio when bluetooth headphones disconnect

Posted: 01 Jul 2022, 08:53
by malcev

Re: Mute audio when bluetooth headphones disconnect

Posted: 02 Jul 2022, 05:05
by BoBo
SendMessage (Command)
WM_MESSAGEINDEX, ...where WM_DEVICECHANGE := 0x0219
Send-/PostMessage (Tutorial)

HTH 8-)

Re: Mute audio when bluetooth headphones disconnect

Posted: 02 Jul 2022, 07:29
by malcev
BoBo, You dont need to send this message.
You need to receive notification about this message from Your bluetooth device.
qwerty12 alreay did it for usb and We need to do the same with our bluetooth device handle and capture GUID_BLUETOOTH_RADIO_IN_RANGE event, I think.
https://docs.microsoft.com/en-us/windows/win32/bluetooth/bluetooth-and-wm-devicechange-messages