Bluetooth fix for December update

I have OSMC installed on a Raspberry Pi 2 and configured to act as an A2DP sink for streaming audio from my smartphone. After installing the December update, this stopped working. I tried re-pairing the phone, but this made no difference.

After some investigation, I was able to find the problem and get audio working again and I was encouraged to share the solution here.

I opened /etc/bluetooth/audio.conf and replaced it with the following contents:

[General]
Enable=Gateway,Source
Master=true
Disable=Socket
AutoConnect=true

[Headset]
HFP=true

After rebooting and re-pairing the device another time, things were working again.

1 Like

I have also experienced this issue, also my phone which used to connect to OSMC on my Raspberry Pi 2 will not connect via bluetooth.

Thanks @nathan-osman for sharing your solution. I will give it a go when I get home tonight and update back here on how I go with getting bluetooth audio working again.

I’m just curious though and I don’t understand all the settings so I’m just trying to understand. How did you know what to enable/disable in the [General] section of the audio.conf file? I did a little bit of searching and found that there are other settings that can be enabled/disabled such as:

  • Control
  • Sink
  • Headset

Why did you not use these and what made you select just the ones that you used?

Thanks for the feedback.

For completeness, could you describe what the problem turned out to be and what you did to fix it. We can see the end result, but don’t know how/why you got to this point.

It would also be useful if you could tell us the make/model of the bluetooth device.

Upon further investigation, I’m not sure this actually solved the problem. The issue seems to happen intermittently and it appears to be related to PulseAudio being started at boot.

If I boot OSMC and PulseAudio is running, I can connect to A2DP with my phone. If PulseAudio is not running, it fails. I tried running bluetoothctl and running a few commands to confirm that this is the case.

Out of curiosity, how is PulseAudio supposed to be started in OSMC? I can’t find a systemd unit file for launching it.

If it helps, I am using the official OSMC bluetooth dongle into my Raspberry Pi 2. Prior to the latest December release I was able to connect both my iPad and Samsung Galaxy S5 separately to OSMC and stream Spotify over bluetooth to OSMC from either device. It didn’t work perfectly all the time, but I realised that this functionality was still in development.

Now since updating to the latest December release I am unable to connect my phone (Samsung Galaxy S5) to OSMC at all. My iPad will connect, but when I attempt to play music through the Spotify app on the iPad there is now no option to send the audio to OSMC :slightly_frowning_face:.

I have not tried the solution mentioned at the top of this topic, and now I’m not sure that I should try it…

I’ve noticed this too - it seems that OSMC doesn’t advertise the A2DP profile if PulseAudio isn’t running at the time of device pairing. One thing I’ve had some level of success with is ssh-ing into the device and running pulseaudio --start before pairing.

It’s a case of it being advertised too late. To work around this in Debian Jessie, I used to run PulseAudio as a system service. This has its own issues however, and was completely unusable in Debian Stretch due to internal changes.

I spent a lot of time trying to chase this down to preserve behaviour as much as possible before the update, but could not work it out entirely.

The solution in the long term is to abandon this approach altogether as PulseAudio introduces another poorly understood level of abstraction.

Sam

Thanks for the update Sam :slightly_smiling_face:. So to summarise, at this stage Bluetooth A2DP streaming does not and will not work, but in the long term something will be developed that doesn’t require PulseAudio?

By the way, thanks for all your hard work on this latest release! Absolutely love OSMC and am excited by the future developments and features that you and your team are working on!

It works. Sort of. I wonder if bodging it to run as the OSMC user permanently as a systemd unit is enough to get the advertisements working. The problem is that currently PA is socket activated, so by the time it starts, it can be too late.

Annoyingly there wasn’t much we could do to salvage things with this release. But with Stretch out of the door, we can look at it again and share ideas. A few of us on the team were testing it but as always the more testers the better.

The long term plan is indeed to move away from PA.

Thanks for the kind words

Sam

That explains a lot. Could a unit file be created that runs a command at startup to activate the socket?

The problem is if we run it as OSMC user it can’t be consumed by anyone else.
I suppose a systemd unit with osmc as user might work, but did not try this approach.

Sam

Hi !

It’s a case of it being advertised too late. To work around this in Debian Jessie, I used to run PulseAudio as a system service. This has its own issues however, and was completely unusable in Debian Stretch due to internal changes.

Diagre with “completely unusable in Debian Stretch due to internal changes”, my solution for pulseaudio in system mode:

  1. Remove pulse systemd user units, puseaudio.service and pulseaudio.socket

  2. create system pulseaudio unit like this:
    [Unit]
    Description=Sound Service
    [Service]
    Type=notify
    ExecStart=/usr/bin/pulseaudio --daemonize=no --system --disallow-exit --log-target=syslog --high-priority
    Restart=on-failure
    [Install]
    WantedBy=default.target

  3. Add osmc user to groups: pulse-access, pulse, audio

  4. Change /etc/pulse/client.conf, set: autospawn = no

Kill currently running pulseaudio, start system pulseaudio unit, restart mediacenter.
Now connect BT headset, and set PA defaul sink (as osmc user), this lines from
my script:

pactl set-card-profile bluez_card.${1} a2dp_sink
pactl set-default-sink bluez_sink.${1}.a2dp_sink

Select pulseaudio playback in kodi settings.

Agree with Sam, that pulseaudio is “crutch for a healthy leg”.
Tried to use this:

but kodi can’t init audio device, does not know why, aplay work as expected.

Bluez-alsa does not simulate a device but is a plug-in. Can’t say I understand the difference, but hopefully the project will get some love now Raspbian is packaging it.

@Den4t

Thanks for your findings. Prior to moving to Stretch, I was also using a custom system unit to start PulseAudio in system mode. It did work.

However on Stretch, even when we tried this approach, we had problems with keys and permissions. I’m not sure why – but did spend a large amount of time on it. We set the correct groups and permissions via postinst of our package. One thing I did notice however was that manually invoking PulseAudio via the CLI just once and killing it solved this problem thereafter; but this was not ideal.

I compared the state of the filesystem before and after; but never found any clues as to what was actually happening.

This is the commit which reverts the old system approach. See

Perhaps a second pair of eyes may show what’s wrong.

I will revisit it later at some point

Sam

I think, osmc need to be in group “pulse” too, not just in “pulse-access”, because
system unit work as pulse user:

osmc@pi:~$ ps axo user,group,pid,command|grep pulseaudio
pulse pulse 274 /usr/bin/pulseaudio --daemonize=no --system --disallow-exit --log-target=syslog --high-priority

and:

osmc@pi:~$ ls -ald /var/run/pulse
drwxr-xr-x 3 pulse pulse 120 Feb 10 21:44 /var/run/pulse

I also added the osmc user to the “audio” group, but not sure it is necessary,
and “autospawn = no” (from my first post) in pulse client.conf no needed, just checked it.

I have given up on A2DP and I am now using a Avantree aptX LOW LATENCY Bluetooth 4.2 Transmitter for TV PC (3.5mm, RCA wired to the RCA of a Dac+ due to the low volume and quality of sound from the pi3 headphone socket.
this is very stable as the dongle is USB powered and connects on switch on every time.
Happy days

I can produce some packages if you’d like to test – but they’d need to be tried on a fresh installation.

Sam

I’m looking for Bluetooth transmitter like Avantree, i don’t know about low quality of headphone socket of PI.

@darkvader1 Can you link me in private about your Dac+?

Although I always have so much hope for a A2DP resolution…

Can do a fresh install if needed.