Tiny project - Listen to your music library anywhere
For all the folks out there who do not use spotify or google music, there is always this problem of having to carry your music somewhere somehow and have a limited choice on your music selection that you want to carry with you. With a Raspberry pi and an attached USB disk you can now easily have access to your library with a web and streaming client on your cellphone or desktop.
The stack that will allow us to do this is an mpd daemon, which will take care of managing the library and controlling the music, which in turn will also encode and connect to our second pilar of this neat architecture, an icecast server so that it can be heard as a stream. The ympd web client will take care of having a neat interface to control the mpd daemon. To access the ympd web client, nginx as a reverse proxy was the obvious choice as it is very lightweight, this also enables us to have ssl encryption and basic user authentication. The only issue that I have found so far and did not dug deep further into it is that due to the fact that you are buffering your stream, when you change music, stop it or press play to hear it, sometimes it takes up to 15 seconds for the change to reach your listening device. I can live with this, although it is a small nuisance.
Below my config file for MPD with some comments:
### Self explanatory section
# This takes care of connecting to the icecast server.
# The type is 'shout' since icecast is a fork of shoutcast.
name "my cool stream"
# I had to add this as mpd was nagging about not having a decent interface for output.
name "fake out"
Now, for the horrible icecast configuration based on XML I am only going to paste here the only interesting part that I have added.
This allows for the stream to fallback to another music file. This is due to the fact that when you setup a playlist on ympd it will stop the stream and start again, leaving your streaming client hanging and disconnecting from the stream. Annoying.
Now that we have all these configuration files set and dusted, we need to make sure that this thing stays up and running if it crashes or after a reboot. I really like to use supervisord for these things.
Here are my ympd-david and mpd-david configuration files for supervisor:
command=/usr/bin/mpd --stdout --no-daemon --verbose /home/david/.config/mpd.conf
command=/usr/bin/ympd -h localhost -p 6604 -w 8904 -u david
This is pretty lightweight and a Raspberry Pi can easily run this for yourself or for the whole family if you want to, I sure am having fun being able to listen to my music anywhere without ads or resorting to other music providers ;-).