Sunday, 22 April 2018

Multiroom RPi Music server using Pure Jongos

Requirement

There are only a million RPi music server projects so I am sure there is room for 1,000,001.  I already have speakers in a number of rooms for the radio, hifi and sound bar and they work well so I don't want to duplicate or replace them.  Current systems are all a few years old so don't have built in bluetooth connectivity. However I would like to be able to use bluetooth and listen to the same music throughout the house and to have the entire music collection in one place.
Sonos is the current vogue for multi-room music.  Music is stored on a NAS or PC and each device stores an index of available tracks and their location.  It is controlled via a phone app which does not need to be active unless you want to change something.  It is not suitable for my requirement due to the need to buy lots of hardware but the music server approach seems good.
I am very fond of the Pure Jongo A2 bluetooth hifi adapter.  It attaches to any music device with phono inputs and allows you to play music from your phone or tablet using bluetooth.  It can also route music from NAS or internet radio channels to a sound system.  It also has a wonderful feature called "caskeid" which shares music between Jongo devices so that you can listen to the same sounds in multiple rooms.  There are Jongo speakers which can add sounds in extra rooms or outside.  These features make Jongo an excellent basis for a multi-room system but there are a couple of catches.  Firstly, your phone/tablet needs to stream the music to Jongo.  You can't move it to a different room or turn it off.  Secondly Pure appear to have lost the multi-room battle to Sonos and are discontinuing their Jongo range.  In fact this means prices for that  A2s (£20) and speakers (£50-£150) are reasonable on Amazon or Ebay so it makes for an affordable system.

Design

Hardware

I currently have a RPi which is used as a NAS so it makes sense to use it as a music server as well.  The current device is B+ so I need to plug in a USB bluetooth adapter which will communicate with one of the Jongos.
I already have three Jongo A2 attached to my study HiFi, TV sound bar and kitchen mini-system so these will form the core of the playback system.  I will add a Jongo speaker and another A2 to allow two more rooms to be linked in.  I may buy another outdoor specification Jongo for use in a bathroom.  All devices will be setp via the Pure Connect app with caskeid so that they synchronise playback.

Software

RPi software setup will comprise the bulk of the project.  The obvious music server to use is MPD which is a long-term component of linux.  It plays music from multiple sources, namely local disks or network URLs which may represent web music (http), NAS (smb) or streams (pls).  Files can be added into playlists (m3u).  Mopidy was investigated as a popular alternative to MPD but doesn't seem to have important extra features.
An advantage of using MPD is that it is a standard product so there are many clients available to control it (play/pause, create/load playlists, etc).  MPDroid or M.A.L.P can be used on Android, MPDluxe (£2.99) on IoS and Auremo was chosen for the Windows as I have previously found it useful.  In addition to these platform specific apps there is a small package called ympd which runs as a small RPi python web server to allow MPD to be controlled from a browser window.  There are other web-based clients but they have more complex/specific requiremetns for web-server, database etc.  As a backstop the standard linux music client MPC can be used via an ssh session (mobaxterm/putty on Windows, reflection on iPad) or at the RPi console / GUI.
The RPi will continue to be used "headless" so generally the GUI will not be present, although it is useful during testing.
I have found bluetooth and audio routing problematical on RPi previously.  Bluetoothctl and pulseaudio for sound routing are pretty standard so I will need to make them reliable.

Media

Existing music collection stored on large USB stick will be available, I would also like to setup a number of radio streams and access playlists in my Rplay no-advert radio system.

Installation

This is intended to be a reasonably high-level description of the installation in April 2018 on PI3, a RPi B+ running Raspbian Stretch.

Step 1 Software installation

Bluetooth software on RPi has changed a lot of the past two or three years with new versions of raspbian so it is best not to use old tutorials, this one seems quite recent.

Update linux: # apt-get update;apt-get upgrade; apt-get dist-upgrade; rpi-update
Install bluetooth/pulse audio: # apt-get install blueman pulseaudio pulseaudio-module-bluetooth
Install music software: # apt-get install mpd mpc mpg123

Step 2 Sound testing

I don't have speakers connected to PI3 by default so initially I connected some and made sure that playing an mp3 file using the command line player mpg123 resulted in sounds.  Note that not all mp3 players support .mp3 files and many don't recognize pulseaudio, so mpg123 is a good choice.
I also used the GUI initially.  There are bluetooth icons on the menu bar on the top right of the screen.
I made sure that my Jongo A2 was visible by running bluetooth setup from the icon and ensuring it was paired and trusted but not connected.  Then, right-clicking on the speaker icon and selecting the bluetooth speaker caused the bluetooth speaker to burst into life.  There was some trial and error involved, in particular pulseaudio didn't always seem to be running which prevented bluetooth being used with mpg123.  Once this step is complete we know that we can play music on PI3 through a bluetooth speaker using the GUI.

Step 3 MPD Music Server

MPD (Music Player Daemon) is a venerable but widely used music server for Linux.  It contains a database of song titles and plays to a music device.  MPC (Music Player Client) is the corresponding  linux command line client software which allows music to be started, stopped, re-indexed and playlists to be managed. As installed MPD doesn't support pulseaudio properly because pulseaudio is running as pi and cant communicate with the mpd user.  The wiki explains how to setup MPD so it streams to localhost (127.0.0.1) which pulseaudio can read and send to bluetooth.
Once mpd is setup music can be stored in /var/lib/mpd/music. CIFS/SMB shares on other devices can be accessed by specifying mount points in /var/lib/mpd/music.  For example I setup a mount point for my RPi NAS at /var/lib/mpd/music/rpipmusic/ with:
 sudo mount -t cifs /<nas ip>/<nas share>/ /var/lib/mpd/music/rpipmusic / -o user=x, pass=x
In addition MPD accepts urls as file locations.  These may be http://server/folder/song.mp3 or streaming radio URLs.

Step 4 Play music with MPC

Once some music has been placed in /var/lib/mpd/music use the command mpc update to index it and make the music available. It is fiddly to do this entirely using mpc but it is still the fastest way of getting started. mpc ls will show you what folders and playlists are available.  You should see your music there.    mpc listall <foldername> will show you what is available in the folder (e.g. an album).  mpc add <foldername>  will add files in <foldername> and any sub-directories to your playlist which you can then show with mpc playlist.  Finally mpc play tells mpd to start playing the music and mpc pause or mpc toggle stops it.

Conclusion

At this stage we have a music server playing through a bluetooth speaker so we have met our key technical requirements.  There is a lot more we can do to improve the system which I will summarise in the next posting.










No comments:

Post a Comment