This gist describes a means of getting mpd (music player daemon) to auto-play when it starts. This may be of interest to those (like me) using computers like the Raspberry Pi as a music player connected to a stereo amp.
There's probably a way of getting mpd to auto-play directly, but I haven't found it. My solution was therefore to create a daemon init script which starts after mpd, and which uses mpc (an mpd client) to start mpd playing. If you've got mpd configured to store its state on exit, this means that it should start at the same place in the play list as when it shut down.
These instructions use the LSB init mechanism, which is supported by Debian (and variants, such as Raspbian). It should be trivial to convert them to using the standard SysV init mechanism, if you want.
- A distro with support for LSB init scripts (see intro)
- mpd (installed, and starting via an LSB init script)
- mpd configured to store playing state (probably via the
state_file
setting in/etc/mpd.conf
, or wherever the config is on your system) - mpc (installed)
Note: these instructions are for a Raspberry Pi system running Volumio (volumio.org)
Log in as root, and install the mpd-autoplay file:
# cp /where/you/put/mpd-autoplay /etc/init.d/mpd-autoplay
# chmod 755 /etc/init.d/mpd-autoplay
# insserv mpd-autoplay || echo "Oops - failed to install!"
The last line ensures that the script is executed whenever the system starts, after mpd is running.
To test without restarting the box:
- Ensure that mpd is running, with some songs in the playlist
- Pause playback in mpd, via whatever client you use
- Execute the following as root:
service mpd-autoplay start
, and mpd should start playing again.