#!/bin/bash
length=$(dcop amarok player trackTotalTime)
if [[ $length != 0 ]]
then
	dcop amarok playlist setStopAfterCurrent 1
	while $(dcop amarok player isPlaying)
	do
		sleep 1
	done
else	# radio : gradually lower
	vol0=$(dcop amarok player getVolume)
	vol=$vol0
	time=20	# time in seconds for 100%
	while [[ $vol != 0 ]]
	do
		dcop amarok player setVolume $(($vol-$((100/$time)) ))
		sleep 1
		vol=$(dcop amarok player getVolume)
	done
	dcop amarok player pause
	dcop amarok player setVolume $vol0
fi
dcop amarok MainApplication-Interface quit
kshutdown $1
exit 0
