30

I have a nice bluetooth audio receiver connect to my HiFi stereo, and I used to be able to connect it in 14.04 as a A2DP sink with nice quality.

After upgrading to 16.04, the device connects only as headset, and when trying to switch it in A2DP mode, I have this error in my syslog:

May 21 11:35:50 RRyS pulseaudio[6159]: [pulseaudio] module-bluez5-device.c: Refused to switch profile to a2dp_sink: Not connected

and the quality of audio is abismal. How can I fix it?

Rmano
  • 31,947
  • Hope this is useful to somebody. I have lost 3 hours digging into it... I love upgrades! ;-) – Rmano May 21 '16 at 10:34

3 Answers3

41

What works for me is to connect the bluetooth device, switch to HSP/HFP mode, disconnect, reconnect and then switch to A2DP mode.

rmfought
  • 411
36

There are several bugs opened about this, check for example this one (started in 15.05) and this other one, quite older; the causes in general are not well understood.

Before starting modifying system files, you can also check Bluetooth speaker no sound in Ubuntu 16.04 (seems a different bug) and A2DP bluetooth doesn't work on 16.04 (solved in comments by a kernel upgrade).

The fix that worked for me is the following --- thanks to user RobertFM in launchpad and SimFox3 in Arch forums. All the following instructions must be executed from a root shell (sudo -i). Take care and triple check.

  1. First of all, make a backup of these files (you never know):

    cp /etc/bluetooth/audio.conf /etc/bluetooth/audio.conf.bak
    cp /etc/pulse/default.pa /etc/pulse/default.pa.bak
    cp /usr/bin/start-pulseaudio-x11 /usr/bin/start-pulseaudio-x11.bak
    
  2. Edit /etc/bluetooth/audio.conf and make it similar to this one:

    # Configuration file for the audio service
    # This section contains options which are not specific to any
    # particular interface
    [General]
    Enable=Gateway,Source
    
    # Switch to master role for incoming connections (defaults to true)
    Master=true
    
    # If we want to disable support for specific services
    # Defaults to supporting all implemented services
    #Disable=Gateway,Source,Socket
    Disable=Socket
    
    # SCO routing. Either PCM or HCI (in which case audio is routed to/from ALSA)
    # Defaults to HCI
    #SCORouting=HCI
    
    # Automatically connect both A2DP and HFP/HSP profiles for incoming
    # connections. Some headsets that support both profiles will only connect the
    # other one automatically so the default setting of true is usually a good
    # idea.
    AutoConnect=true
    
    # Headset interface specific options (i.e. options which affect how the audio
    # service interacts with remote headset devices)
    [Headset]
    
    # Set to true to support HFP, false means only HSP is supported
    # Defaults to true
    HFP=true
    
    # Maximum number of connected HSP/HFP devices per adapter. Defaults to 1
    MaxConnected=2
    
    # Set to true to enable use of fast connectable mode (faster page scanning)
    # for HFP when incoming call starts. Default settings are restored after
    # call is answered or rejected. Page scan interval is much shorter and page
    # scan type changed to interlaced. Such allows faster connection initiated
    # by a headset.
    FastConnectable=true
    
    # Just an example of potential config options for the other interfaces
    #[A2DP]
    #SBCSources=1
    #MPEG12Sources=0
    
  3. Edit /etc/pulse/default.pa and comment out the line

    #load-module module-bluetooth-discover
    

    (you really only need to add the # at the start)

  4. Edit /usr/bin/start-pulseaudio-x11 and add the line /usr/bin/pactl load-module module-bluetooth-discover after the loading of the module module-x11-xsmp; in practice you should edit the file near the end to have a stanza like

    if [ x"$SESSION_MANAGER" != x ] ; then
        /usr/bin/pactl load-module module-x11-xsmp "display=$DISPLAY session_manager=$SESSION_MANAGER" > /dev/null
        # add this line here:
        /usr/bin/pactl load-module module-bluetooth-discover
    fi
    
  5. Reboot.

    Now you should be able to set your device to A2DP and enjoy high quality music:

    Sound settings

    Notice that sometime you need to Disconnect and Reconnect your device to re-enable A2DP:

    Bluetooth devices

    ...yes, it's a can of bugs. But when it works it works beautifully.

  6. Troubles after reboot

    After all of this, sometime the trick seems to work just only after the next reboot. In such a case, try to follow rmfought's answer:

    What works for me is to connect the bluetooth device, switch to HSP/HFP mode, disconnect, reconnect and then switch to A2DP mode.

    ...works for me too (again, sometime). I had to even un-pair a re-pair the dongle once.

  7. If it still doesn't work...

    If this also isn't working for you, you can try with this script --- its author is keeping it up-to-date.

Eliah Kagan
  • 117,780
Rmano
  • 31,947
  • 5
    audio.conf is not present in ubuntu 16.04, only main.conf, will that work? – Joakim Koed May 31 '16 at 16:30
  • 2
    @JoakimKoed --- you're right, I checked --- I had a audio.conf-remove probably remnant from the upgrade. I simply recreated it --- so now I am in doubt, maybe just points 3 and 4 are necesssary? – Rmano May 31 '16 at 16:38
  • 1
    Steps 3 & 4 did not fix for me, and I recreated audio.conf as per the above and no fix. Deleting the bluetooth device and repairing fixes, but doing that every time you want to use bluetooth audio is not feasible. – Thomas Carlisle Jun 15 '16 at 02:08
  • @ThomasCarlisle sorry to hear that - here it worked (no need to re-associating) after the first time. Must be a different thing... – Rmano Jun 15 '16 at 06:07
  • You are a rockstar – Attila Fulop Sep 29 '16 at 10:29
  • doesn't work for me and my Polaris V8 bluetooth speaker. no audio.conf and creating one doesn't help. Only steps 3 and 4 also don't change anything – weelux Oct 11 '16 at 10:51
  • This worked for me. I didn't have an audio.conf but I did have an audio.conf.dpkg-remove so I copied that back to audio.conf and modified as described by Rmano. – bjmc Oct 14 '16 at 17:52
  • Only partial solution. Worked the first reboot. Then turned off the headset to save battery as I was not using it, and when I reconnected the headset only get mono sound. Dropping down the menu in sound settings to select A2DP just switches back to the speakers. So it's either mono or nothing for me. It's a shame that in 2016 bluetooth support in Linux is still light years away from its competitors. I mean, even Android (a Linux per se) does this out-of-the-box... – romanovzky Oct 25 '16 at 12:53
  • @romanovzky --- try also rmfought's answer --- fixed it to me when sometime it happens after the reboot. – Rmano Oct 25 '16 at 14:25
  • Also, this doesn't seem to work if you have an application using sound, like youtube on a browser, vlc, etc. You seem to have to close all of them to perform the disconnect and connect trick. Any ideas on how this can be workedaround? – romanovzky Nov 01 '16 at 14:06
  • 1
    Brilliant! It does the trick with me! I suggest you add a reference to it in your answer, as all together seems to give a fully working solution to the problem. Cheers! – romanovzky Nov 08 '16 at 09:24
5

This is not necessarily a solution for those who need the mic, but this worked in Ubuntu 16.04 for me:

sudo nano /etc/bluetooth/audio.conf

And then add Disable=Headset under [General].

[General]
Disable=Headset

And restart the bluetooth service

sudo service bluetooth restart

And all the creds to this guy: https://jimshaver.net/2015/03/31/going-a2dp-only-on-linux/

Eliah Kagan
  • 117,780
helgis
  • 51
  • Unluckily, didn't work out for me. My bluetooth dock icon is greyed out… Maybe it's the driver/module? XPS 13 9350 and ubuntu 16.04. – Dolanor Oct 16 '16 at 07:55
  • @Dolanor Not sure wether this is still a problem, but a if the dock icon is greyed out, it most likely means that your bluetooth-adapter is softblocked. Try rfkill unblock bluetooth and maybe even bluetoothctl and then power on (in the bluetoothctl-CLI). – FMaz Mar 21 '17 at 14:33
  • This worked in my case zorinos 12 – FDisk Mar 28 '18 at 13:51
  • On Ubuntu 18, there is no /etc/bluetooth/audio.conf file. I added Disable=Headset to /etc/bluetooth/main.conf, restarted the service, reconnected my headphones, but the audio profile was by default off. Not sure this worked? – Dan Dascalescu Jun 22 '19 at 04:50