[SOLVED] Bluetooth Headphones No Sound After Auto-Connect

Questions about codecs, DVD playback, web plugins...
Forum rules
Before you post please read how to get help
Post Reply
Rakantor
Level 1
Level 1
Posts: 4
Joined: Tue Sep 24, 2019 10:16 am

[SOLVED] Bluetooth Headphones No Sound After Auto-Connect

Post by Rakantor »

Hi,

I recently installed Mint 19.2 Cinnamon and tried to connect my Sony WH-1000XM3 Bluetooth Headphones. The pairing worked fine and A2DP was selected by default. However, when I turn the headphones off and on again, they auto-connect but no sound is being played through them. Instead all sound keeps playing through my speakers. I opened the Sound Settings, clicked on my headphones and noticed the "Output profile" is empty. I can select A2DP there but the change is not being applied.

One thing that works is to open the Bluetooth Manager and manually disconnect & reconnect the headphones, but that gets really annoying after some time. There has to be another solution.

I'm grateful for any help.
Last edited by Rakantor on Wed Sep 25, 2019 6:09 pm, edited 1 time in total.

User avatar
MrEen
Level 18
Level 18
Posts: 8024
Joined: Mon Jun 12, 2017 8:39 pm

Re: Bluetooth Headphones No Sound After Auto-Connect

Post by MrEen »

Hi Rakantor, and welcome to the forum.

Install and run PulseAudio Volume Control. You can switch the output on the Playback tab when sound is playing. Note that there won't be anything to switch if sound is not currently playing.

If you want to get real fancy, you can run pacmd list-sinks to find out the index numbers of the available sinks, then run pacmd list-sink-inputs to get the index numbers of the actively playing inputs, then switch where it's playing to with pacmd move-sink-input #OfSinkInput #OfSink

An example, the first output shows your Built-in analog-stereo as index: 0 and the Bluetooth device as index: 4 Then the second command shows something like this:

Code: Select all

1 sink input(s) available.
    index: 17
    driver: <protocol-native.c>
Then to move the output from the speakers to the BT device, run pacmd move-sink-input 17 4 and to switch it right back run pacmd move-sink-input 17 0

Be aware that each time you play something with sound, the index number from pacmd list-sink-inputs gets higher. I haven't rebooted in almost 2 weeks, and mine just returned index: 7067

Usually, but not always, the index numbers from the first command will remain the same, at least until the next reboot.

Hope that helps.

Rakantor
Level 1
Level 1
Posts: 4
Joined: Tue Sep 24, 2019 10:16 am

Re: Bluetooth Headphones No Sound After Auto-Connect

Post by Rakantor »

The problem is that apparently my Bluetooth headphones aren't recognized as an audio device after reconnecting them to my PC. When I switch them on they are shown as "Connected" in the Bluetooth Manager, but in pavucontrol there is no entry for them. Running pacmd list-sinks returns "2 sink(s) available", missing the Bluetooth headphones.

As I mentioned before, I have to manually disconnect & reconnect the headphones in the Bluetooth Manager each time. After doing that they appear in pavucontrol and pacmd list-sinks returns "3 sink(s) available".

User avatar
MrEen
Level 18
Level 18
Posts: 8024
Joined: Mon Jun 12, 2017 8:39 pm

Re: Bluetooth Headphones No Sound After Auto-Connect

Post by MrEen »

Next time it happens, see if running pulseaudio -k in the terminal makes the device appear.

Rakantor
Level 1
Level 1
Posts: 4
Joined: Tue Sep 24, 2019 10:16 am

Re: Bluetooth Headphones No Sound After Auto-Connect

Post by Rakantor »

Running pulseaudio -k disconnects the headphones.

User avatar
MrEen
Level 18
Level 18
Posts: 8024
Joined: Mon Jun 12, 2017 8:39 pm

Re: Bluetooth Headphones No Sound After Auto-Connect

Post by MrEen »

I'm afraid I don't know enough about Bluetooth. I'll see if I can find something else to try.

Rakantor
Level 1
Level 1
Posts: 4
Joined: Tue Sep 24, 2019 10:16 am

Re: Bluetooth Headphones No Sound After Auto-Connect

Post by Rakantor »

Thanks for your effort MrEen, I appreciate it!
I was able to come up with a solution after some hours of searching the web and trying different things.

I came across this: Bluetooth headphones only use A2DP when connected manually
And then found this: Udev service for temporary solve bug 92102

I now no longer need to manually disconnect & reconnect my headphones every time in order to play sound through them.

Here's what I did step by step.

1. Install dependencies

sudo apt install bluez-tools expect perl systemd-container

2. Create a shell script

nano /home/<USER>/.config/bt-auto-enable-a2dp.sh

Code: Select all

#!/bin/bash

# Dependencies:
# * bluez-tools
# * expect
# * perl

function enable_a2dp() {
	# run connect command in bluetoothctl and wait for resolve of services
	expect <<< "
		spawn bluetoothctl
		send \"connect $mac\r\"
		log_user 0
		expect -re \".*Device $mac ServicesResolved: yes\"
	"
	# enable card in pulseaudio
	pactl set-card-profile $pulsecard a2dp_sink
	logger -p info "mac $mac enabled"
	headsetname=`bt-device -l | perl -ne '/(.*) \('$mac'\)/ and print "$1\n"'`
	notify-send 'Headset connected' "$headsetname" --icon=blueman-headset
}
function search_headsets() {
	sleep 1
	# in all added devices
	for mac in `bt-device -l | perl -ne '/.*\((.*)\)/ and print "$1\n"'`
	do
		# search for connected device with AudioSink service
		if [[ `bt-device -i $mac | perl -00 -ne '/.*Trusted: 1.*\n\s*Blocked: 0.*\n\s*Connected: 1\n\s*UUIDs: .*AudioSink.*/ and print "1\n"'` ]]; then
			logger -p info "found mac: $mac"
			# convert mac to pulse card name
			pulsecard=`perl -pe 's/:/_/g' <<< "bluez_card.$mac"`
			enable_a2dp
		fi
	done
	echo "search done"
}
logger -p info "${BASH_SOURCE[0]}"
# get script owner name
user=`stat -c %U $0`
if [ "$user" == `whoami` ]; then
	# if script runned by owner - start main function
	search_headsets
elif [ "`w -hs $user`" ]; then
	# else if user session exist(to prevent running on system startup) - run script from user
	machinectl shell --uid=$user .host ${BASH_SOURCE[0]}
fi
chmod +x /home/<USER>/.config/bt-auto-enable-a2dp.sh

3. Create a systemd service pointing to the script

sudo nano /etc/systemd/system/bt-auto-enable-a2dp.service

Code: Select all

[Unit]
Description=Bluetooth headphones auto enable A2DP

[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/home/<USER>/.config/bt-auto-enable-a2dp.sh

[Install]
WantedBy=multi-user.target
4. Create a custom udev rule

sudo nano /etc/udev/rules.d/20-bt-auto-enable-a2dp.rules

Code: Select all

# /etc/udev/rules.d/20-bt-auto-enable-a2dp.rules
SUBSYSTEM=="bluetooth", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="bt-auto-enable-a2dp.service"
sudo udevadm control --reload-rules

5. Reboot

User avatar
MrEen
Level 18
Level 18
Posts: 8024
Joined: Mon Jun 12, 2017 8:39 pm

Re: [SOLVED] Bluetooth Headphones No Sound After Auto-Connect

Post by MrEen »

Nice work Rakantor!!

I'm so glad you found a solution.

Enjoy. :D

User avatar
BG405
Level 8
Level 8
Posts: 2023
Joined: Fri Mar 11, 2016 3:09 pm
Location: England

Re: [SOLVED] Bluetooth Headphones No Sound After Auto-Connect

Post by BG405 »

MrEen wrote:
Wed Sep 25, 2019 6:18 pm
Nice work Rakantor!!
Indeed! :mrgreen: This may well help pthers (and myself, probably) .. bookmarked for future reference.
Dell Inspiron 1525 - LM17.3 CE 64-------------------Lenovo T440 8GB - Manjaro KDE with Mint VMs
Toshiba NB250 - Manjaro KDE------------------------K7S5A AMD 1.2GHz - LM17.3 Xfce 32 & WinXP-Pro
Acer Aspire E11 ES1-111M - LM18.2 KDE 64 ----Dell PII 350 64MB - Puppy 4.3 & Win98-SE

Post Reply

Return to “Sound, Multimedia, & Codecs”