#!/bin/sh
# Executes mplayer with fifo input event control;
# Date: 2009-10-25;
# Michael Pozhidaev <msp@altlinux.org>

if ! [ -r /etc/mplayer-control.conf ]; then
    echo "/etc/mplayer.conf not found. Exiting..."
    exit 1
fi
. /etc/mplayer-control.conf

# Checking if mplayer is already running:
[ -e $MPLAYER_FIFO ] && exit 0

exit_handler()
{
	local rc=$?
	trap - EXIT
	rm -f -- "$MPLAYER_FIFO"
	exit $rc
}

trap exit_handler EXIT HUP INT QUIT PIPE TERM
set -e
mkfifo $MPLAYER_FIFO
/usr/bin/mplayer -softvol -vo null -input "file=$MPLAYER_FIFO" "$@" > /dev/null 2> /dev/null
