Close
0%
0%

Multiroom Music Streaming

I am using Raspberry PIs and Pulseaudio for synchronous music streaming in my appartment.

Similar projects worth following
The goal of this project is to have an easy to use solution for multi room audio streaming, like the products from sonos, but less expensive.
It should be able to run on Raspberry PIs and must be integrable into my Home Automation System, for example when entering a room, the music shall switch to that room.

My music streaming solution is based on Mopidy, which has a spotify plugin and can run on a Raspberry PI.

After some fiddling with Mopidy and Icecast 2, I realized that Icecast can't satisfy my requirement of synchronous streaming: While moving from one room to another, I don't want the audio to skip back or forward.

So I finally choose pulseaudio as the streaming companion for mopidy, because it supports the Real-time Transport Protocol (RTP), which is exactly made for carrying multimedia streams through the network. This method is also more gentle to the network, because it uses UDP broadcasts and therefore has to send the data only once, no matter how many clients are listening to the stream.

However, my FritzBox did not like this and decided to kill the WiFi after a few minutes streaming. Because the WiFi had quirks before, I upgraded my home network with an TP Link Archer C7, which can handle the traffic without any problem.

The second requirement I have is, to be able to mute and unmute each client quickly from my home automation. To achive this, the client runs a very simple python HTTP server, which can control the output of pulseaudio.

Another challenge was that I am running Libreelec on the Raspberry PI in my bedroom and it has no support for installing additional software. I also want to use PI zeros in the other rooms, so the software must work on both without changes. Because of this, I decided to use Docker, which is fortunately preinstalled on Libreelec and also has with Hypriot a great image for the Raspberry PI.

Getting the audio output and RTP broadcast to work in docker felt quite tricky, but with a few parameters (--net=host and --privileged) it was dead simple. The net=host parameter lets the container use the host network, so you don't have to configure anything. Also it is the only method I know to enable sending and receiving udp broadcasts, without having to configure the host. The privileged option allows the container to access the host devices, especially the audio devices.

I created an docker image for the server, which contains mopidy and pulseaudio and a second image for the client, which contains pulseaudio alongside the control server. Both can be downloaded from Docker Hub and run by a single command.

  • 1
    Step 1

    Install Hypriot on your Raspberry PIs: http://blog.hypriot.com/downloads/
    You need at least one Raspberry PI 2 or better for the server and some other Raspberry PI with ethernet, e.g. a Raspberry PI zero with adapter, for each client.

  • 2
    Step 2

    ssh into the server pi and run

    docker run --restart=always -d --net=host -e USER='YOUR SPOTIFY USERNAME' -e PASS='YOUR SPOTIFY PASSWORD' malted/mopidy-pulseaudio-server

    Replace the USER and PASS values with your spotify credentials.

    The default login for hypriot is pirate with the password hypriot.

  • 3
    Step 3

    Direct your Browser to IP_OF_YOUR_SERVER_PI:6680 and start a song.

    It will be broadcasted on 224.0.0.56:45678. You can use vlc to check it.

    vlc rtp://224.0.0.56:45678
    

View all 6 instructions

Enjoy this project?

Share

Discussions

JahFyahh wrote 06/13/2017 at 22:26 point

is there a way to get this to work with an android app?

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates