Making a2dp default when headset connects

Asked by Evren Yurtesen

I have a bluetooth headset and when it connects, it routes audio to it by default fine. But it selects hsp profile instead of a2dp, I am able to change it from the sound control panel or from command line using pactl to a2dp. I am using kodi on this box so I would like to get a2dp automatically without bothering with going to command line and back. So how can I manage to do this? I tried many different setting combinations at /etc/bluetooth/audio.conf but it didnt help much. I am using Ubuntu 14.04.3 LTS. I found other posts related to this and tried everything which is mentioned in those without success.

I think either I should be able to somehow tell pulseaudio to use a2dp by default although it has lower priority OR run a script when the bluetooth device connects which runs the command to change to a2dp (but how?)

Card #1
        Name: bluez_card.00_0D_FD_35_78_D1
        Driver: module-bluetooth-device.c
        Owner Module: 20
        Properties:
                device.description = "Motorola S305"
                device.string = "00:0D:FD:35:78:D1"
                device.api = "bluez"
                device.class = "sound"
                device.bus = "bluetooth"
                device.form_factor = "headset"
                bluez.path = "/org/bluez/809/hci0/dev_00_0D_FD_35_78_D1"
                bluez.class = "0x240404"
                bluez.name = "Motorola S305"
                device.icon_name = "audio-headset-bluetooth"
                device.intended_roles = "phone"
        Profiles:
                hsp: Telephony Duplex (HSP/HFP) (sinks: 1, sources: 1, priority. 20)
                a2dp: High Fidelity Playback (A2DP) (sinks: 1, sources: 0, priority. 10)
                off: Off (sinks: 0, sources: 0, priority. 0)
        Active Profile: off
        Ports:
                headset-output: Headset (priority: 0, latency offset: 0 usec)
                        Part of profile(s): hsp, a2dp
                headset-input: Headset (priority: 0, latency offset: 0 usec)
                        Part of profile(s): hsp

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Evren Yurtesen (eyurtese-g) said :
#1

I now came up with a python script which listens to dbus and with a shell script to switch to a2dp. Is there any better solution? I think it is strange that this basic operation requires messing with scripts etc. the headphones work perfectly on windows and with android.

/usr/local/bin/switch_a2dp.sh
--------------------------------------------------------------------------------------------------
#!/bin/sh

DISPLAY=:0
export DISPLAY
pactl set-card-profile `pactl list cards short|grep bluez|awk '{print $1;}'` a2dp
--------------------------------------------------------------------------------------------------

/usr/local/bin/switch_a2dp.py
--------------------------------------------------------------------------------------------------
#!/usr/bin/python

import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject

import subprocess
import time

def cb(action,result,interface=None):
    if (action=="Connected" and result==1 and interface=="org.bluez.Headset"):
        time.sleep(5)
        subprocess.call(['/usr/local/bin/switch_a2dp.sh'])

bus = dbus.SystemBus(mainloop=DBusGMainLoop())
bus.add_signal_receiver(cb, bus_name="org.bluez", signal_name="PropertyChanged",
                dbus_interface="org.bluez.Headset", interface_keyword='interface')

loop = gobject.MainLoop()
loop.run()
--------------------------------------------------------------------------------------------------

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

I suggest you report a bug. You can post your script as a solution

Can you help with this problem?

Provide an answer of your own, or ask Evren Yurtesen for more information if necessary.

To post a message you must log in.