#!/bin/sh

mod=$1
if [ "$mod" = "" ] ; then
   mod=0
fi

#first, if a cd is playing, pause/unpause it 
case "$mod`cdinfo`" in
	0paused*)
		exec cdplay
		;;
	0play*)
		exec cdpause
		;;
	1no-status*)
		exec cdplay
		;;
	2*)   #if modifier set to 2, then stop the cd instead of pausing. Ignore state of xmms in this situation
		exec cdstop
		;;
esac

if [ "$mod" = "0" -o "$mod" = "1" ] ; then
	xmmsstatus=`xmmsstatus`
	if [ "$xmmsstatus" = play ] ; then
	    exec xmms --pause
	elif [ "$xmmsstatus" = stop ] ; then
	    exec xmms --play
	fi
fi

#if not, try getting xmms to unpause/pause the mp3 track


#if not, the last chance we have is to play a stopped cd. Nothing will happen if there is nothing in the cdplayer.
#if second modifier pressed, but xmms not running, try cd player again
cdplay
