Secondary Menu

Enhance Raspberry Pi Media Center With Bluetooth A2DP (OSMC)

Having Bluetooth connectivity and enabling Raspberry Pi to behave as A2DP source is nothing new (see a general tutorial on Instructables), but the problem I had thus far was making that work on my media center Pi which was running Raspbmc. As I found out through numerous attempts to make it work, the problem was with Raspbmc suffering a bit too much from "weight loss" it forced upon itself, so the modules that work as expected on Raspbian were failing on Raspbmc:

When I learned that Raspbmc was not going to be developed any longer and that its successor -- OSMC -- will be based on Debian distro that was not butchered to fit on 2 GB SD card, I immediately planned to give that a try :-)

What I found out when I started setting up A2DP on OSMC on my Raspberry Pi 2 is that OSMC is no longer based (as its predecessor was and as Raspbian is) on Debian Wheezy, but that it is based on Debian Jessie. That means bye-bye SysVinit and hello Systemd. And that change of service manager (making all "A2DP on Rasberry Pi" available tutorials obsolete or at least not easily replicable by novice users) is the real reason for this tutorial.

Step 2: Log in to a Terminal

1) Variant: Remote terminal (SSH)

If you've a LAN connection to the Pi, the easiest way to go through this tutorial is to use SSH -- they you can copy/paste commands instead of typing them :-)

Find what your Pis IP address is and SSH into it with your favorite telnet client.

2) Variant: Local terminal

In this case, connect your keyboard, go to Power menu in XBMC and choose Exit. XMBC will close in a few seconds, but will restart immediately again. To enter the terminal, make sure you press the ESC key after you've choosen the Exit and while the OSMC screen is still showing. That will stop XBMC from staring again ad you'll have a terminal prompt with login in front of you.

Either way, the default credentials for OSMC are:

Username: osmcPassword: osmc

Step 3: Install the Necessary Packages

To get the state of repositories up-to-date, first execute:

sudo apt-get update

Optional: if you want, you can upgrade the outdated packages with:

sudo apt-get upgrade

Note: OSMC uses its own apt-get repository (http://apt.osmc.tv) for updating the system, which is a welcome change from Raspbmc, so not only does 'upgrade' upgrades the linux distro and installed 3rd party packages, it also upgrades the OSMC (media center and its packages).

Heads-up: from this point forward, the tutorial uses GNU nano as terminal text editor, but you can easily use the one you prefer.

Open the configuration file for the PulseAudio daemon:

sudo nano /etc/pulse/daemon.conf

And find (press Ctrl+W, then type 'float') the line that reads:

resample-method = speex-float-1

and change it so:

; resample-method = speex-float-1
resample-method = trivial

Because we'll be running PulseAudio deamon in system mode, loading additional modules will not be possible once the deamon is started, so we need to configure their inclusion in the PulseAudio startup script for system mode:

sudo nano /etc/pulse/system.pa

and add the following lines (which check for existance and enable various modules):

Up to now, this is still the same as the usual getty@.service file, but the most important part is to modify the autologin@.service to actually log you in automatically. To do that, you only need to change the ExecStart line to read:

ExecStart=-/sbin/agetty -a osmc %I 38400

That's it. After this you'll briefly see the login prompt when the OSMC boots up, but it will allow PulseAudio to run even without you logged in.

Step 7: Conclusion and Tips

My main goal was to reuse the always-on devices (media centar Raspberry Pi and Android phones/tablets) to stream online subscription music (namely Google Play Music) without needing to have PC turned on or the client device jacked in.

Naturally, the setup can be used to stream all sorts of audio through Pi. For example, gaming on tablet sounds pretty sweet when played on home stereo :)

Tip:

What I encountered occasionally on the phone was that sometimes it doesn't automatically reconnect to the Pi and that, when Pi (osmc) is pressed in BT phone settings, it immediately disconnects. The solution for this seems to be to turn BT on the phone off and then back on. After that (BT "reset") the phone again automatically connects to the Pi.

Nota bene:

I was writing down each step I applied while I was investigating how goal in this tutorial can be achieved, but when I started to verify the tutorial (on a clean OSMC install) some weeks later, the version of the OSMC was incremented and I didn't manage to reproduce it exactly step by step, so if you find some parts are off, feel free to suggest improvements in the comments (and I will hopefully update the tutorial).

Okay, I've tried my best to blend together both the instructions above and the suggestions below and still cannot get any audio output.

I'm using a R Pi 1 Model B while I wait for a dedicated model 3 to arrive with the OSCM July 1st image. I'm starting to wonder if something has changed in the bluetooth architecture because the folder '/etc/bluetooth' is not there and the file 'main.conf' does not exist either. I went ahead and did a 'mkdir /etc/bluetooth' and created the main.conf file with the contents suggested but that doesn't seem to have fixed the issue.

I've also tried changing the Audio Out settings in OSMC and none of them will produce the bluetooth audio either...

Thanks for the great instructions. Went through them step by step and everything works! Now.. I'm interested in another addition which I think might be very much welcome by other users as well - have the BT connect event trigger an HDMI CEC message to the connected AVR / TV and get it to turn on...

My existing RPi2 + OSMC does exactly that when turned on (including AVR input change) but when I connect to its BT from a client and stream audio it doesn't..

I thought that enabling Raspberry Pi as A2DP source means to send data to be played on an A2DP sink such a bluetooth headset or speakers. But step 1 says I must connect headphones or speakers to the 3.5mm port. What is this tutorial for?

For me it worked when reverting from RC3 to RC, but after restarting the device(pi) is not detected as a ad2p speaker but rather a normal Bluetooth device(with no label). When tryign to connect to it the connection would drop after less than a second.

I believe it may be the ad2p configs are not taking effect, but am unsure as I followed the guide exactly.

Hi, I am having the same problem. It used to work fine for a couple of days, then when the pi rebooted, my bluetooth device is now Class 0x00041C and cannot be connected to anymore.

The file /var/lib/bluetooth/XX:XX:XX:XX:XX/settings seems to get overwritten at boottime where the line Class = 0x20041C gets erased. I can manually set the device class back to 0x20041C using "hciconfig hci0 class 0x20041C" but I have to do this after every reboot.