A2DP bluetooth doesn't work on 16.04 [duplicate]

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?


Solution 1:

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

Solution 2:

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.