Pulseaudio not detecting bluetooth headset automatically

The Pavucontrol on my Xubuntu 13.10 detects my bluetooth headset, but only after I type the commands :

pulseaudio -k
sudo alsa force-reload

After a few seconds the headset appears in the configuration tab.

I have also tried inserting the line

load-module module-switch-on-connect

in the /etc/pulse/default.pa but it doesn't help. I have tried purging and autoremoving and reinstalling everything right from alsa to pulseaudio and pulseaudio-module-bluetooth. Nothing works.

Is there a workaround to load the headset without using the command force-reload ? To make the pulseaudio daemon recognize the device automatically ?

I tried adding :

    pcm.bluetooth {
    type bluetooth
    device "XX:XX:XX:XX:XX:XX"
    profile "auto"
   }

to a file .asoundrc in my home directory but it doesn't make a difference

After killing the pulseaudio daemon, my even volume hotkeys stop working. I have to assign

amixer set Master 4%- -q unmute
amixer set Master 4%+ -q unmute

to some other key combination to manage the volume from keyboard. Assigning the commands to the hotkeys doesn't work. How are the volume keys bound to the daemon ? Is there any other way of binding the keys to the new daemon (after restarting) ?

UPDATE

Found the problem. Using the command

pactl list | grep -i module-bluetooth-discover

I found out that the bluetooth discover module was not loaded.

But my default.pa file in /etc/pulse contains the lines

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

So why does the module not load on pulseaudio startup ?

After issuing the command

sudo pactl load-module module-bluetooth-discover

The bluetooth headset works properly and is detected automatically, without killing and restarting alsa.


Solution 1:

I found a fix for this on another answer, the problem is that the pulseaudio bluetooth module is loaded before X11, changing a couple of config files do the trick: PulseAudio can not load bluetooth module 15.10/16.04/16.10

vim /etc/pulse/default.pa

Comment out (with an # at the beginning of the line) the following line:

#load-module module-bluetooth-policy
#load-module module-bluetooth-discover

Now edit the file /usr/bin/start-pulseaudio-x11 find the following lines:

   if [ x”$SESSION_MANAGER” != x ] ; then
    /usr/bin/pactl load-module module-x11-xsmp “display=$DISPLAY session_manager=$SESSION_MANAGER” > /dev/null
   fi

and change them to this:

   if [ x"$SESSION_MANAGER" != x ] ; then
    /usr/bin/pactl load-module module-x11-xsmp "display=$DISPLAY session_manager=$SESSION_MANAGER" > /dev/null
   #
   # Added per StackExchange http://askubuntu.com/questions/366032/pulseaudio-not-detecting-bluetooth-headset-automatically
   #
    /usr/bin/pactl load-module module-bluetooth-policy
    /usr/bin/pactl load-module module-bluetooth-discover
   fi

This way the Pulse audio’s Bluetooth modules will not be downloaded at boot time but after x11 is started.

This fix goes against the current suggestion at: https://freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Bluetooth/

Solution 2:

This:

sudo apt-get install pulseaudio-module-bluetooth 
sudo pactl load-module module-bluetooth-discover

worked for me on Ubuntu 14.10 (Lenovo x240) to have at least my bluetooth device listed in pulseaudio.

Solution 3:

It seems there is an issue with some (legacy?) code in Blueman which deliberately unloads module-bluetooth-discover on startup (i.e. after it's been loaded from /etc/pulse/default.pa. For more details see here: https://github.com/blueman-project/blueman/issues/64.