Skip to content

Instantly share code, notes, and snippets.

@attilagyorffy
Forked from captsens/mpd-autoplay
Created March 24, 2015 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attilagyorffy/aa2afdb0d0acf2fa8ec8 to your computer and use it in GitHub Desktop.
Save attilagyorffy/aa2afdb0d0acf2fa8ec8 to your computer and use it in GitHub Desktop.
#!/bin/sh
### BEGIN INIT INFO
# Provides: mpd-autoplay
# Required-Start: mpd
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Ensures that mpd plays on startup
# Description: Starts after mpd, and uses the mpc client to tell mpd to play
### END INIT INFO
#
# Requires mpd and mpc
#
# To install, use 'insserv mpd-autoplay'
. /lib/lsb/init-functions
case "$1" in
start)
mpc play
;;
stop|restart)
;;
status)
echo "Nothing to see here, move along..."
;;
*)
echo "Usage: $0 start|stop|restart|status"
exit 2
;;
esac

Introduction

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.

Requirements

  • 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)

Instructions

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment