23

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?

11 Answers 11

19

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

  • >>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 9: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
  • 2 years later and this answer was needed for me with my Sony WH-H900N. – Joakim Wimmerstedt Oct 14 '18 at 16:08
13

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

pacmd list-cards
pacmd set-card-profile <index> <profile>
  • 1
    Using ubuntu 16.04 /etc/bluetooth/audio.conf does not excist, where should i write this line instead? – thebeancounter Nov 4 '17 at 16:25
  • This fixed it for me on Debian Sid, thank you! – espectalll Apr 21 '18 at 12:45
  • @thebeancounter add the file if it does not exist – Jimubao Jul 19 '18 at 1: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 1:47
12

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.

  • 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 2:12
  • This worked for me on ZorinOS - Thanks – FDisk Apr 24 '18 at 7:35
  • I did the second workaround from that link from Debian, works like a charm! – Amfasis 2 hours ago
4

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>'
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
2

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
  • This answer and @freespace one helped me on my i3 setup – Luis Lobo Borobia Jun 29 '18 at 0:02
1

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 8 '18 at 21:10
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.

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."
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
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?

0

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.