I'm using MPD as a center of my Home's music system (sort of a open source alternative to Sonos).
The biggest problem so far has been that MPD can only play either static music files or HTTP streams. There is no way to stream TO the MPD. For example, I wanted to stream podcasts from my phone (where I already have a good podcasting setup) to my home audio system.
So after some research and a whole lot of trial and error, I came up with this bodge of a setup where I have an Airplay receiver (shairport-sync), whose input eventually gets converted into a HTTP stream that MPD can consume.
The way to do this is to install and enable shairport-sync, set its config file to stream all the audio as raw CD audio into into a unix pipe, and then set it to call start.sh script when the streaming starts and end.sh script then the streaming from the phone stops.
pipe =
{
name = "/music"; // this is the default
};
sessioncontrol =
{
run_this_before_play_begins = "/scripts/start.sh";
run_this_after_play_ends = "/scripts/end.sh";
}
Start script:
#!/bin/sh
# Start a vlc instance that will read raw CD audio from the /music pipe fed by the shairport-sync and convert it into the HTTP audio stream that MPD can play
# Nohup will ensure that VLC keeps the stream up even after this script finishes
nohup su -- vlc -c "cvlc -vvvv --demux=rawaud --rawaud-fourcc=s16l --rawaud-channels 2 --rawaud-samplerate 44100 /music :sout='#gather:transcode{acodec=mp3,ab=192,channels=2,samplerate=44100}:http{mux=dummy,dst=:6604/sound.mp3}' --sout-mux-caching=100 --http-caching=100 --sout-ffmpeg-rc-buffer-size=100 :sout-keep :repeat" &
# Wait for the vlc to start
sleep 1
# Stop existing playback on the MPD
mpc --host $MPD_IP clear
# Add stream created above by the VLC to the playlist of the MPD
mpc --host $MPD_IP add http://$MY_IP/sound.mp3
# Start the playback
mpc --host $MPD_IP playEnd script:
#!/bin/sh
# Stop the VLC server
pkill vlc
# Check what the MPD is currently playing
CURRENT_SONG=$(mpc --host $MPD_IP current)
# If the MPD is still playing our stream, then stop it
if echo "$CURRENT_SONG" | grep -q "http://$MY_IP/sound.mp3"; then
mpc --host $MPD_IP stop
fiUnfortunately I'm not using the setup much at the moment, because it has a considerable latency, caused by the buffering on the mpd that is not configurable. This means that every pause/skip forward etc. will be only heard after a few seconds.