Music Player Daemon Community Wiki


522pages on
this wiki
Add New Page
Talk4 Share

This script will start playing a jingle after the currently playing file. This can be used - for instance - to play a 'top of the hour' jingle.

# MPD script to play a song (a jingle for instance) after the currently playing song.
# The intention is to let this script get started by a cronjob.
# Written by Marcel van der Schans inspired by by Harun Vos.

# Requires mpc - set the path here.

# Extract the interesting line from the mpc output.
# There must be a nicer way of dealing with multi-line shell variables.
function getDetailsLine()
  local d=$($MPC --format "no file name")
  d=$(tail -1 <<EOL
$(head -2 <<EOL2
  echo $d

# Get the playing/paused status.
function getStateFromLine()
  echo $*|cut -d' ' -f1

# Get the number of the currently playing song.
function getSongFromLine()
  echo $*|cut -d' ' -f2|cut -d'/' -f1|cut -d'#' -f2

# Get the number of the last song / the length of the playlist.
function getLastSongFromLine()
  echo $*|cut -d' ' -f2|cut -d' ' -f1|cut -d'/' -f2

# Dont do anything if we arent playing.
currState=$(getStateFromLine $details)
if [ "$currState" != "[playing]" ]; then exit; fi

# Add jingle to (end of) playlist.

# Refresh our details line

currSong=$(getSongFromLine $details)
lastSong=$(getLastSongFromLine $details)

# Move the last song (our jingle) to the next entry.
let nextSong=currSong+1
$MPC move $lastSong $nextSong

To let this script get started at a specific time (i.e. every hour), you can use crontab. Note that crontab uses the sh shell and doesn't load all your settings at the .profile file. To be able to run the script - which is written for the bash shell - you can call the following (intermediate) script from crontab:

# Place the location of the script below.
bash /home/username/

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.