Snapcast: [Question] Setting up Bluetooth A2DP audio sink

Created on 4 Apr 2018  路  20Comments  路  Source: badaix/snapcast

I have a pi3 which runs snapserver and snapclient. Mopidy and librespot both run well. Now I wanted to add a2dp to the pi3. I followed this gist which is using bluealsa.

So my understanding is that I need to configure Alsa to write another fifo file in /tmp. But when I add /etc/asound.conf as described here I dont hear anything from my pi3. Only snapclients connected play correctly. When reverting the changes to asound.conf everything except bluetooth is working again. Can someone give me an hint what I did wrong? Thanks!

Most helpful comment

@fuchsmich It's been a long time and maybe you aren't interested in this anymore but this is my latest, not completely finished addition to my snapcast family:
test
It's a multiroom bluetooth box (has batteries to be able to perfom without a psu) and quite usefull in a flat ;)

All 20 comments

I guess, the error is in the first line of /etc/asound.conf, it makes /tmp/snapfifo the systemwide default sink for players using alsa. So snapclient is playing back to snapserver.

Suggestion: On Pi3 run snapclient and bluez-alsa with different users and put /etc/asound.conf as ~/.asoundrc into the home of the user which runs bluez-alsa.

Another solution would be to append asound.conf from here to your existing /etc/asound.conf but without the first 4 lines, which make the rate plugin default, and choose rate48000Hz as output device for bluez-alsa.

Setting up a new user did the trick. Thanks for the hint @fuchsmich !

Just to be sure: you are streaming via bluetooth to RPi3 and from there via snapserver to other clients?

If yes, this is an awesome idea and does it work fine?

Awesome idea, but didn't work flawless for me. Always had some hickups, seems to be related to RPi3 and using both build in bluetooth and wifi at the same time. My solution is to use an external bluetoth receiver and feed it by a line in into the RPi and Snapcast

It is working that way @fuchsmich. I'm mainly using spotify (librespot) but also have other sources like google music, german radio audio library and some youtube playlist. For these I wanted a bluetooth connection to the rpi3. I testest all my usecases and it's working well. I didn't notice any problems at all (besides my technical shortcomings).

@derglaus: Known problem which is easy to fix. I'm using the ethernet connection of my pi since it is near my router. Do you experience issues with your external receiver?

In general I really like the multiroom solution. I recently added nodes and was surprised how cheap and easy the process was. Buy a zero w, PCM5102A, PAM8610 and throw in some old speakers and a psu (I 3d printed cases as well). Since I had another node I just needed to take an image and flash it to the new ones. Change the hostname - that's it. Very convenient :)

Snapcast is such an amazing project. It's a pity, that my flat is so small. ;) I'm just using it for living room and kitchen.

But I defenitly got to try this streaming via bluetooth.

I'm using the pi zero, so no cable lan...
For now it works fine. Pi zero + fe-pi as server, pi zero + hifiberry as client, either the android app or my own webinterface (on any client and/or a dedicated pi+touchscreen) to control the system

@fuchsmich It's been a long time and maybe you aren't interested in this anymore but this is my latest, not completely finished addition to my snapcast family:
test
It's a multiroom bluetooth box (has batteries to be able to perfom without a psu) and quite usefull in a flat ;)

@herrwusel can you explain me a bit how did you manage to run snapclient and bluez-alsa to different user please ?

Sure.
Create a user and place said config inside the newly created home directory:

$ cat /home/bluemusic/.asoundrc 
pcm.!default {
        type plug
        slave.pcm rate48000Hz
}

pcm.rate48000Hz {
        type rate
        slave {
                pcm writeFile # Direct to the plugin which will write to a file
                format S16_LE
                rate 48000
        }
}

pcm.writeFile {
        type file
        slave.pcm null
        file "/tmp/bluesnapfifo"
        format "raw"
}

Change the service file from the gist to the newly created user:

$ cat /etc/systemd/system/a2dp-playback.service 
[Unit]
Description=A2DP Playback
After=bluealsa.service syslog.service
Requires=bluealsa.service

[Service]
ExecStartPre=/bin/sleep 3
ExecStart=/usr/bin/bluealsa-aplay --profile-a2dp 00:00:00:00:00:00
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=A2DP-Playback
User=bluemusic

[Install]
WantedBy=multi-user.target

That should be it.

Ok ! And I can let the settings needed for my sound card :

pcm.!default {
type hw
card 0
}
ctl.!default {
type hw
card 0
}

In my /etc/asound.conf so ?

I didn't change it iirc.

And your configuration in /etc/default/snapserver seems like this no ? :
SNAPSERVER_OPTS="-d -s pipe:////tmp/bluesnapfifo?name=Bluetooth&mode=read"
Cause i still get no sound, even for my slave :/

SNAPSERVER_OPTS="-d -s pipe:///tmp/bluesnapfifo?name=Bluetooth"
This works for me. You might have a / too many.

I managed to get this working in buster :D but how do you resolve choppy music in snapclient if music is sent through BT to snapserver?

I'm trying to follow your path
My problem is about files acces rights
the bluesnapfifo is created by another user (which I named btstreamer) and snapserver started by the main user (pi) cannot access it
The problem is that I don't know how to change the permissions on the bluesnapfifo file once its created as this is done from the .asoundrc file

And if you try to add the user pi to the group bluetooth by
sudo adduser pi bluetooth ?

Its already the case ;-)
The only temporary solution I've found is to chmod the file bluesnapfifo after its created but I 'd like to get a clean solution instead.

Of course !
You should try to re-install the Bluetooth side with this kind of thing : https://github.com/nicokaiser/rpi-audio-receiver
I've use it, and everything is working for me

I think that the problem does not come from the bluetooth stack but from file permissions !

Was this page helpful?
0 / 5 - 0 ratings