57

I have currently installed ubuntu 16.04 and a2dp used to work on fresh install, which I'd prefer to leave as a last option. When the pairing is erased from bluetooth settings and is paired again sometimes it manages to be on a2dp profile, but if the headset is disconnected and then reconnected the a2dp profiles doesn't work anymore (though it says is on a2dp), it only works after switching to HSP/HSF and then I'm unable to set it on a2dp.

I have tried doing:

 pacmd set-card-profile <index> a2dp_sink

but the following error comes out:

"Failed to set card profile to 'a2dp_sink'"

I'm quite inexperienced in Linux so I don't know how to get logs or what to look for in them, but I got this from pacmd list-cards:

When it works:

name: <bluez_card.50_C9_71_97_A1_86>
driver: <module-bluez5-device.c>
owner module: 27
properties:
    device.description = "Jabra REVO a4.0.0"
    device.string = "50:C9:71:97:A1:86"
    device.api = "bluez"
    device.class = "sound"
    device.bus = "bluetooth"
    device.form_factor = "headset"
    bluez.path = "/org/bluez/hci0/dev_50_C9_71_97_A1_86"
    bluez.class = "0x240404"
    bluez.alias = "Jabra REVO a4.0.0"
    device.icon_name = "audio-headset-bluetooth"
    device.intended_roles = "phone"
profiles:
    headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: unknown)
    a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: unknown)
    off: Off (priority 0, available: yes)
active profile: <a2dp_sink>
sinks:
    bluez_sink.50_C9_71_97_A1_86/#6: Jabra REVO a4.0.0
sources:
    bluez_sink.50_C9_71_97_A1_86.monitor/#10: Monitor of Jabra REVO a4.0.0
ports:
    headset-output: Headset (priority 0, latency offset 0 usec, available: unknown)
        properties:

    headset-input: Headset (priority 0, latency offset 0 usec, available: unknown)
        properties:

When it doesn't:

name: <bluez_card.50_C9_71_97_A1_86>
driver: <module-bluez5-device.c>
owner module: 25
properties:
    device.description = "Jabra REVO a4.0.0"
    device.string = "50:C9:71:97:A1:86"
    device.api = "bluez"
    device.class = "sound"
    device.bus = "bluetooth"
    device.form_factor = "headset"
    bluez.path = "/org/bluez/hci0/dev_50_C9_71_97_A1_86"
    bluez.class = "0x240404"
    bluez.alias = "Jabra REVO a4.0.0"
    device.icon_name = "audio-headset-bluetooth"
    device.intended_roles = "phone"
profiles:
    headset_head_unit: Headset Head Unit (HSP/HFP) (priority 20, available: unknown)
    a2dp_sink: High Fidelity Playback (A2DP Sink) (priority 10, available: yes)
    off: Off (priority 0, available: yes)
active profile: <off>
ports:
    headset-output: Headset (priority 0, latency offset 0 usec, available: yes)
        properties:

    headset-input: Headset (priority 0, latency offset 0 usec, available: unknown)
        properties:

And the owning module is:

name: <module-bluez5-device>
argument: <path=/org/bluez/hci0/dev_50_C9_71_97_A1_86>
used: 0
load once: no
properties:
    module.author = "João Paulo Rechi Vita"
    module.description = "BlueZ 5 Bluetooth audio sink and source"
    module.version = "8.0"

I have already tried to modify /etc/bluetooth/audio.conf and install blueman but it didn't work. I also tried to reinstall bluez and pulseaudio but nothing changed.

Is there any way I can know what's wrong and fix it?

  • could you please explain where do you get this info from ? and what is index? thanks! – Ezequiel Moreno Feb 19 '17 at 22:02
  • Check here http://askubuntu.com/a/817926/33292 – pylover Mar 12 '17 at 18:33
  • 1
    I had similar problems using my legacy Plantronics Backbeat Pro headset and a general bluetooth adapter on Debian Buster. The solution was to use the original Plantronics BT600 USB to bluetooth adapter in stead of the general bluetooth adapter. Hope this helps some one. – Yapsr Nov 17 '20 at 12:15

15 Answers15

51

In order to allow your system to be detected as an A2DP sink (e.g. to play music from your phone via your computer speakers), add Enable=Source,Sink,Media,Socket under [General] in /etc/bluetooth/audio.conf.

After doing this, restart the bluetooth daemon

systemctl restart bluetooth

Connect you headphone device

bluetoothctl
connect <MAC>

Check your card and set profile

pactl list cards short
pacmd set-card-profile <index> <profile>
SebMa
  • 2,291
Jimubao
  • 611
  • 3
    Using ubuntu 16.04 /etc/bluetooth/audio.conf does not excist, where should i write this line instead? – thebeancounter Nov 04 '17 at 16:25
  • This fixed it for me on Debian Sid, thank you! – Xerz Apr 21 '18 at 12:45
  • @thebeancounter add the file if it does not exist – Jimubao Jul 19 '18 at 01:08
  • occasionally if you lost connection with A2DP sink, try "power off" in bluetoothctl and then "systemctl restart bluetooth" and after that in bluetoothctl "power on" and connect your device again – Jimubao Aug 14 '18 at 01:47
  • 11
    Worked on ARch / Manjaro ! Yet the file is now located at /etc/bluetooth/main.conf for recent version – MCMZL Mar 23 '19 at 10:53
  • I have been through so many threads, blog posts, wiki pages, issues etc. on and off to no avail and this fixed it for me. I'm on Arch with bluez version 5.54 using a "CB3 Hush" wireless headset (since some of the posts I've found allege it's an issue with particular headsets). As MCMZL indicated I did add this to /etc/bluetooth/main.conf instead. – Dylan May 19 '20 at 23:20
  • Thanks. It worked for my Linux Mint 20.1 with the Ugreen usb bluetooth dongle! – Trung Ta Sep 16 '20 at 03:59
  • Just systemctl restart bluetooth alone worked for me when my headphones randomly had lower audio quality. – Fabian Röling Mar 05 '21 at 22:07
  • 1
    If this answer stops working for you, try the most highly voted answer to this question: basic, add Disable=Headset rather that what described in the answer above to the file /etc/bluetooth/main.conf – HongboZhu Mar 25 '21 at 20:35
  • Thanks! That worked in Ubuntu 20.04, although the file is now /etc/bluetooth/main.conf – happyskeptic May 05 '21 at 12:08
  • I just added Enable=Sink, because I never want it to be anything else. I'll report back if that breaks something, but currently it seems to work. – Fabian Röling Aug 13 '22 at 22:37
  • I initially couldn't find a2dp profile in my pacmd cards list but adding Enable in the /etc/bluetooth/main.conf did the trick. Thanks! – Saeed Ahadian Oct 27 '23 at 11:00
34

Based on the line "active profile: <off>" the sound profile didn't activate.

One program that is easy to use to change the profile is pavucontrol. You can install it with sudo apt install pavucontrol -y. Then run pavucontrol from the command line or Alt+F2 if you are on Kubuntu and entering pavucontrol.

Select the configuration tab and then try changing the profile for your headphones and see if that updates for you. There seem to be a bug with bluetooth a2dp still in linux and it affects two of my 16.04 installations. If it already says A2DP change it to OFF, disconnect the device in the bluetooth applet, then reconnect it. Then finally proceed to change the profile back to A2DP and it should work.

You can also try the following on the command line and it should tab complete most of it for you. Replace the number 2 with the index number currently for both pacmd commands below.

pacmd set-card-profile 2 off
bluetoothctl
disconnect 50:C9:71:97:A1:86
connect 50:C9:71:97:A1:86
pacmd set-card-profile 2 a2dp_sink

For a more complicated but automated way of doing the same thing for cycling the profile to off and then back to a2dp but not do the bluetooth device disconnect and connect

index=`pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'`
pacmd set-card-profile $index off
pacmd set-card-profile $index a2dp_sink 

I was also to make a working but sloppy script to do the same thing but also disconnect and reconnect the bluetooth headphones. It grabs the profile index because the index changes every time the device is disconnected and reconnected. This is hardcoded with the device id for the headset you listed above

pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` off
sleep 2
echo -e "disconnect 50:C9:71:97:A1:86\n quit"|bluetoothctl
sleep 5
echo -e "connect 50:C9:71:97:A1:86\n quit"|bluetoothctl
sleep 5
pacmd set-card-profile `pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}'` a2dp_sink

During testing I ended up with the 5 seconds for sleep instead of 3 because the device wasn't ready to change the audio profile yet. Your results may vary by a few seconds +/- 5 seconds. Edit regarding a potential pitfall. I did find that it's is occasionally needed to run the larger script twice before it works. I'm not sure if increasing the sleep times would help or not as I haven't tested that. But I have used it on two machines with the same brand of BT headphones and it's doing what it's supposed to for automating the process to get the sound working on the headphones.

Eventually the issue will be patched in the bluetooth package but seems to keep returning in new releases of Ubuntu as well as other versions of Linux. But anyhow hope that helps for you

sanmai
  • 630
Jamie S.
  • 341
  • 2
  • 3
  • How can I see the logs and figure out whats wrong?<< Would be great if you could also answer this question :)

    – kitingChris Jan 20 '17 at 09:30
  • Set sound to bluetooth headphones in pavucontrol gui works for me. Works better that Gnome sound tool. – QkiZ Mar 14 '17 at 19:37
  • 1
    2 years later and this answer was needed for me with my Sony WH-H900N. – Joakim Wimmerstedt Oct 14 '18 at 16:08
  • (1 year later) using XFCE and blueman-manager, I frequently have to bluetoothctl disconnect aa:bb:cc:dd:ee:ff && bluetoothctl connect aa:bb:cc:dd:ee:ff before right-clicking in the Devices menu will allow me to switch the audio profile to A2DP. I also occastionally have to kill a child blueman-manager process when it takes too long to bring up the devices menu. – ericP Jun 17 '19 at 15:21
  • Thanks for providing these commands. This is the only workaround that worked with my Ubuntu 18.04 and Sony WH-1000xm2. I have scripted it on this gist: https://gist.github.com/egelev/2e6b57d5a8ba62cf6df6fff2878c3fd4 – egelev Nov 12 '19 at 12:15
14

I had this problem on Ubuntu 16.04.1 LTS, and applying the GDM work around found in https://wiki.debian.org/BluetoothUser/a2dp solved it.

Specifically, create/edit /var/lib/gdm3/.config/pulse/client.conf to read:

autospawn = no
daemon-binary = /bin/true

Then

sudo chown gdm:gdm /var/lib/gdm3/.config/pulse/client.conf

I also added to /etc/pulse/default.pa

load-module module-switch-on-connect

Though this might not be strictly necessary.

After a reboot, I connected via bluetooth manager was able to successfully switch the audio profile to a2dp_sink.

freespace
  • 241
  • 2
  • 4
  • I had the problem that bluez-firmware was unavailable during the first step in the link, then user gdm cannot be found. Also, the folder gdm3 did not exist, so had to create that entire path. – wordsforthewise Dec 18 '17 at 02:12
  • I did the second workaround from that link from Debian, works like a charm! – Amfasis Feb 21 '19 at 06:59
5

lagerismi posted a script here on launchpad based on the answer by Jamie S.

  • Change the devices MAC-address in the variable inside the script! (can be found with bluetoothctl --> Device)

  • Make the script executable chmod a-x bluetooth_headphone_reactivation.sh

For automatic execution at startup (only works if headset is already turned on):

  • Add the script to the start/shutdown scripts in KDE's control panel

For fast manual execution:

  • Add an entry to the application-starter (you can also set a keyboad shortcut like "CTRL+ALT+H" and/or pin this starter to the window bar)

The script:

#!/bin/sh  
device_mac='<your-devices-mac-address-here>' # From bluetoothctl info
pacmd set-card-profile "$(pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}')" off
sleep 2
echo "disconnect $device_mac\n quit" | bluetoothctl
sleep 5
echo "connect $device_mac\n quit" | bluetoothctl
sleep 5
pacmd set-card-profile "$(pacmd list-cards | grep bluez_card -B1 | grep index | awk '{print $2}')" a2dp_sink
Pablo Bianchi
  • 15,657
5

On Xubuntu 16.04.2
Use blueman-manager:

  1. connect -> set profile off
  2. reconnect -> set profile a2dp
  3. now your headset is ok!

My JBL bash script

#!/bin/bash
#headset mac
mac="00:1D:DF:67:0A:29"
profile="a2dp"
# Special Bluetooth controller, default is empty
btMac=""
#connect|disconnect wait time
waitTime=5

macId="${mac//:/_}"
deviceId="bluez_card.$macId"

declare -A profiles
profiles['a2dp']='a2dp_sink'
profiles['hsp']='headset_head_unit'
profiles['off']='off'

function btCmd() {
    cmd="$1\nquit"
    [ ! -z "$btMac" ] && cmd="select $btMac\n$cmd"
    echo -e "$cmd" | bluetoothctl
}
function setProfile() {
    cmd="pactl set-card-profile $deviceId ${profiles[$1]}"
    echo $cmd
    $cmd
}
function btWaitConnect() {
    conState=$1
    for ((i=1;i<=$waitTime;++i)); do
        tmp="`btCmd "info $mac"|grep 'Connected: '`"
        [ ! -z "`echo "$tmp"|grep $conState`" ] && echo "$tmp" && return 0
        sleep 1s
    done
    echo "$tmp"
    return 1
}
function btConnect() {
    tmp="`btCmd "trust $mac\nconnect $mac" | grep -v 'NEW\|DEL\| quit'`"
    echo "$tmp"

    tmp="`btWaitConnect yes`"
    echo $tmp
    [ -z "`echo "$tmp" | grep yes`" ] && echo -e "Device $mac:\n\tConnected: fail." && return 1
    sleep 2s
    return 0
}
function btDisConnect() {
    tmp="`btCmd "disconnect $mac" | grep -v 'NEW\|DEL\| quit'`"
    echo "$tmp"

    tmp="`btWaitConnect no`"
    echo $tmp
    [ -z "`echo "$tmp" | grep no`" ] && echo -e "Device $mac:\n\tdisconnected: fail." && return 1
    sleep 1s
    return 0    
}


# controller
echo ""
btCtls="`btCmd list | grep '^Controller' | grep " $btMac"`"
echo -e "controller:\n$btCtls"
[ -z "$btCtls" -o ! -z "`echo "$btCtls" | grep "not available"`" ] && exit 1


# connect -> set off
echo ""
tmp="`btCmd paired-devices | grep '^Device' | grep " $mac"`"
echo -e "paired-devices:\n$tmp"
[ `echo "$tmp" | wc -l` != 1 ] && echo "Please pair the Bluetooth headset first: $mac" && exit 1
btConnect || exit $?
setProfile off

# reconnect -> set profile
btDisConnect || exit $?
btConnect || exit $?
setProfile $profile
derHugo
  • 3,356
  • 5
  • 31
  • 51
4

So, if you are using Debian you can do the following: Refused to switch profile to a2dp_sink: Not connected

Problem

Bluetooth headset is connected, but ALSA/PulseAudio fails to pick up the connected device or there's no device to pick. This happens because GDM captures A2DP sink on session start, as GDM needs pulseaudio in the gdm session for accessibility. For example, the screen reader requires it.

Solution

In order to prevent GDM from capturing the A2DP sink on session start, edit /var/lib/gdm3/.config/pulse/client.conf (or create it, if it doesn't exist):

autospawn = no
daemon-binary = /bin/true

After that you have to grant access to this file to Debian-gdm user:

chown Debian-gdm:Debian-gdm /var/lib/gdm3/.config/pulse/client.conf

You will also need to disable pulseaudio startup:

rm /var/lib/gdm3/.config/systemd/user/sockets.target.wants/pulseaudio.socket

In order to auto-connect a2dp for some devices, add this to /etc/pulse/default.pa:

load-module module-switch-on-connect

Reboot.

  • Thank you sir for not following the cargo-cult crowd and actually explaining the issue! I can confirm that this actually helps on Debian stretch. – Marcin Owsiany Jul 08 '18 at 21:10
3

This fixed a set-card-profile issue for me: https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1181106/comments/15

Quote:

1) Modify the /etc/bluetooth/audio.conf
================================

[General]
Enable = Source,Sink,Headset,Gateway,Control,Media
Disable = Socket

HFP=false

[A2DP]
SBCSources=1
MPEG12Sources=0

2) Check for pulseaudio module :
==========================

$ pactl list | grep -i module-bluetooth

If you dont have :
     module-bluetooth-policy
     module-bluetooth-discover
     module-bluetooth-device

Just do :
$ sudo apt-get install pulseaudio-module-bluetooth
$ pulseaudio -k
$ pactl load-module module-bluetooth-device
$ pactl load-module module-switch-on-connect

3) Connect the bluetooth headset
===========================

Use blueman to pair, and connect audio sink
Use pavucontrol to change for A2DP (even if blueman said "audio profile off")

Please confirm that works for you too.
xdevs23
  • 275
2

My problem was solved by this:

mv ~/.config/pulse/ ~/.config/pulse.old
systemctl --user restart pulseaudio
systemctl restart bluetooth
0xF2
  • 3,154
kao
  • 21
  • 2
  • 1
    Although this might solve the problem this does not answer the question asked. They asked how to see the logs. – David Feb 01 '22 at 10:57
1

As documented in here, It is because GDM captures A2DP sink on session start, as GDM needs pulseaudio in the gdm session for accessibility.
Try to add this to "/var/lib/gdm3/.config/pulse/default.pa", or create it, then reboot:

#!/usr/bin/pulseaudio -nF
#

# load system wide configuration
.include /etc/pulse/default.pa

### unload driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
  unload-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
  unload-module module-bluetooth-discover
.endif
masu
  • 103
  • 4
1

None of the solutions described here worked consistently for me since I do not have a fixed schedule when I turn my bluetooth speaker on. Which, if it matters, is a Sony SRS-XB22

But what does work after I connect to my speaker is that I set the card profile to off, small pause and then set it to a2dp_sink.

More precisely, I get the number of the bluetooth device by

pactl list cards short

It's #3 usually right after I start the device, and I just run

pacmd set-card-profile 3 off && sleep 0.5 && pacmd set-card-profile 3 a2dp_sink
Adrian C.
  • 111
  • 2
0

I'm sure that the previous answers actually try to address the root cause of the problem. I, however, was not able to get any of them to work. I had the exact same issue as OP, but on Linux Mint 17/18. I wrote this script to reliably get bluetooth connected and using a2dp.

Copy/pasted for posterity, but the brunt of the matter is that it exactly replicates what the OP (and I) would have to do in the UI.

The script by Dominik wouldn't reliably work for me, because it would only try once to set everything up. I'd have to run it multiple times to get it to work. This is what I ended up with, that works every time.

#!/bin/bash

MAC=$1
CARD=$(echo "${MAC}" | sed -e 's/:/_/g')
CARD="bluez_card.${CARD}"

$(pactl list | grep -qi 'Active Profile: a2dp_sink')
a2dpUsed=$?

# this loops until a2dp is _actually used_ on the given MAC.
while [ ${a2dpUsed} -ne 0 ];
do
    #
    echo "Restarting bluetooth."
    rfkill unblock bluetooth
    sudo service bluetooth restart
    sudo hciconfig hci0 up

    # reconnect
    echo -e "power on\nconnect ${MAC}" | bluetoothctl

    #
    echo "Waiting for headset to be connected..."
    btConnected=1

    while [ ${btConnected} -gt 0 ];
    do

        sleep .1
        $(bluetoothctl <<< "info ${MAC}" | grep -qi "Connected: yes")
        btConnected=$?
    done

    #
    echo "Bluetooth connected, waiting for profiles to register"

    cardFound=1
    while [ ${cardFound} -ne 0 ];
    do
        $(pactl list | grep -qi "${CARD}")
        cardFound=$?
    done

    #
    echo "Setting bluetooth a2dp profile"
    pactl set-card-profile ${CARD} a2dp_sink
    $(pactl list | grep -qi 'Active Profile: a2dp_sink')
    a2dpUsed=$?
done

echo "a2dp is working."
Knetic
  • 131
  • 3
0
systemctl restart bluetooth
  • Open sound settings (accessible by clicking on the speaker icon in the tray)
  • Try and change the Output profile to A2DP Sink.
  • If that doesn't work, change your device to Speakers, or something else and then switch it back.
  • I usually find that I can then set my Output profile
Arthur
  • 231
  • 3
  • 3
0

I chose to solve it with a udev rule, as I am the only user of the system, so $USER, $XAUTHORITY and $DISPLAY are well-known.

Perhaps this is useful for someone that wants a solution defined in a single file, running on Ubuntu 18.04.1 LTS.

The hook is triggered via the input subsystem because the speaker appears to be fully initialized at this stage.

# file: /etc/udev/rules.d/99-jbl-go2.rules
# fix JBL GO2 with CSR bluetooth: switch to a2dp profile upon connect
# byteborg 20190110
SUBSYSTEMS=="input", ACTION=="add", ATTRS{name}=="70:99:1C:41:C6:EB", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/run/user/1000/gdm/Xauthority", RUN+="/bin/su alpha -c '/usr/bin/pacmd set-card-profile bluez_card.70_99_1C_41_C6_EB a2dp_sink'"

The Archlinux Wiki mentions Cambridge Silicon Radio devices providing the wrong profile at connect (https://wiki.archlinux.org/index.php/Bluetooth_headset#A2DP_sink_profile_is_unavailable). I can acknowledge this behaviour with a "JBL GO 2" bluetooth speaker, misbehaving like already mentioned. a2dp seems to be available a short while after connect -- perhaps a timing issue?

byteborg
  • 1,645
  • 1
  • 13
  • 8
0

On Elementary OS Hera 5.1.7 (based on 18.04.4) using kernel 5.8.0-39 (necessary for hardware compatibility reasons), I was able to resolve this issue by

  1. installing pavucontrol and blueman and
  2. editing /etc/bluetooth/main.conf "MultiProfile=multiple" under "general" (see https://wiki.archlinux.org/index.php/Bluetooth_headset#A2DP_not_working_with_PulseAudio) change "AutoEnable=false" (not sure if that did anything)

Before this, I couldn't connect to bluetooth audio sinks, period, unless I used bluetoothctl. At that point, it would only connect to the duplex low quality sink (HSP/HFP) and not A2DP (high audio quality).

Now it appears to be able to work well enough in either mode, with mode-switching on the fly, however, with consistent errors:

[  994.225669] Bluetooth: hci0: urb 0000000085e83e50 submission failed (90)
[  994.225675] Bluetooth: hci0: sending frame failed (-90)
[  994.238145] Bluetooth: hci0: SCO packet for unknown connection handle 0
[  994.238153] Bluetooth: hci0: SCO packet for unknown connection handle 0
[  994.238155] Bluetooth: hci0: SCO packet for unknown connection handle 0
[  994.238157] Bluetooth: hci0: SCO packet for unknown connection handle 0
ethan
  • 314
0

I was trying to set up my Bluetooth and always got this error.

I found that the problem was Skype. If I have Skype running I'm unable to set a2dp_sink profile.

So, if you run into this issue, see if you have Skype running and turn it off.

Zanna
  • 70,465