%
% anyremote configuration file for mplayer management. (Server-mode)
% 
% Thanks Kristjan Ugrin for corrections.
%

% STATUS stable
% XTEST no
% ENV no
% SOUND app
% FBROWSER v.3i
% DEF_VIDEO_PLAYER   
% ALL_IN_ONE 

GuiAppName=MPlayer
GuiAppBinary=mplayer
GuiAppRun=echo 'A=`ps -ef|grep mplayer|grep -v kmplayer|grep -v gmplayer|grep -v grep|grep -v edit|grep -v anyremote`; if [ "x$A" == "x" ]; then echo NOK; else echo OK; fi'|bash -f -s
GuiAppIcon=mplayer.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=A movie player.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
        Include($(CfgDir)/Utils/aliases-server-fbrowser-v3i.cfg);\
	Include($(CfgDir)/Utils/aliases-server-video-player.cfg);\
	Make(var,app_name,by_value,MPlayer);\
	Make(var,open_file,by_value,);\
	Make(var,app_manage_mode,by_value,mplayer);

(Connect)=Make(mode,mplayer_init);

[Mode]=mplayer_init : default_video_player_init

APP_IS_RUN=\
	Make(var,app_run,ID=`id -u`;A=`ps -fu $ID|grep "mplayer -input"|grep -v kmplayer|grep -v gmplayer|grep -v grep|grep -v edit|grep -v anyremote|grep -v "mplayer/fifo"`; if [ "x$A" = "x" ]; then echo 0; else echo 1; fi);

[ModeEnd]

[Mode]=mplayer : default_video_player

% (EnterMode) by Utils/aliases-server-video-player.cfg

APP_SETUP=\
	Exec(if [ -d $HOME/.mplayer ]; then true; else mkdir $HOME/.mplayer; fi; if [ -p $HOME/.mplayer/fifo ]; then true; else mkfifo $HOME/.mplayer/fifo; fi)

APP_START_IF=\
	Set(title,$(open_file));\
	Make(var,app_run,ID=`id -u`;A=`ps -fu $ID|grep "mplayer -input"|grep -v kmplayer|grep -v gmplayer|grep -v grep|grep -v edit|grep -v anyremote|grep -v "mplayer/fifo"`; if [ "x$A" = "x" ]; then echo 0; else echo 1; fi);\
 	Exec(if [ "x$(app_run)" = "x0" ]; then cd "`cat $HOME/.anyRemote/ar_storedir.tmp`";mplayer -input file=$HOME/.mplayer/fifo $(open_file) > /dev/null & fi);

% Application window should be present in output of "wmctrl -l"
APP_RAISE=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh -switch mplayer);

APP_QUIT=\
	Exec(P=`ps -ef|grep "mplayer -input"|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" != "x" ]; then echo quit > $HOME/.mplayer/fifo; fi);\
	Exec(pkill -u `id -u` mplayer);

APP_FULLSCREEN=\
	Exec(echo vo_fullscreen > $HOME/.mplayer/fifo);
	
% Override
1=Exec(echo "volume -10" > $HOME/.mplayer/fifo)
2=Exec(echo mute > $HOME/.mplayer/fifo)
3=Exec(echo "volume +10" > $HOME/.mplayer/fifo)

PLAY=Exec(echo pause > $HOME/.mplayer/fifo);
RWD=Exec(echo "seek -10" > $HOME/.mplayer/fifo);
FF=Exec(echo "seek 10" > $HOME/.mplayer/fifo);
STOP=Exec(echo pause > $HOME/.mplayer/fifo);
PAUSE=Exec(echo pause > $HOME/.mplayer/fifo);

[ModeEnd]

[End]
