Tag: bash
multi-mpd output switcher
by dreamer on May.23, 2009, under Scripts
So, my latest server is now also my music-player. With it I can listen to music at home (it’s attached to my stereo) and also stream it online. On the server I have 2 mpd’s running:
- One as a system-daemon, that anyone can access to control.
- The other runs as user and has a password-protection so only I can modify the playlist (anyone can see the status).
The problem being: How can I listen to both mpd’s on the alsa-output of my server and switch between them with a simple command?
I wrote this little “script” to handle the changes. If you choose to use it, modify according to your settings:
#!/bin/bash
id=$1
## Switch to ‘main’ mpd
if [ $id = main ]
then
## ‘Current’ variables:
export MPD_HOST=<pass-of-user-mpd>@<host>
export MPD_PORT=6601
## Disable and activate main
echo “Switching alsa to main”
mpc disable 1
export MPD_HOST=<host>
export MPD_PORT=6600
mpc enable 1
## Switch to ‘user’ mpd
elif [ $id = user ]
then
echo “Switching alsa to user”
mpc disable 1
export MPD_PORT=6601
export MPD_HOST=<pass-of-user-mpd>@<host>
mpc enable 1
fi
exit 0
Save this to a file in your home-dir. then ‘$ chmod a+x <script>’ and switch with either ‘$ ./<script> main’ or ‘$ ./<script> user’.
If you feel that I have done this very poorly and this could be done better, please comment below ![]()