[MPlayer-users] Binding keys to mplayer?

Jesse F. Hughes jesse at phiwumbda.org
Wed Aug 25 14:26:10 CEST 2004


jesse at phiwumbda.org (Jesse F. Hughes) writes:

> Here's what would work:
>
> (1) Bind (in X) scroll lock to send <space> to the fifo.
>
> (2) In the shell in which mplayer has been started, send every
> keystroke straight to the fifo.
>
> Can I do (2) reasonably?  If not, I could start a small window whose
> sole purpose is to echo to the fifo, I guess.

Here's my solution. 

I wrote a wrapper for mplayer, called mplayer-wrapper.

,----[ mplayer-wrapper ]
| 
| fifo="/tmp/$$.fifo"
| mkfifo $fifo
| mplayer $@ <$fifo &
| echo -n " ">>$fifo
| 
| mplpid=$!
| 
| IFS=""
| while [ -e /proc/"$mplpid" ]
| do 
|   if read -s -t1 -n1  i
|   then 
|     echo -n -e "$i" >>$fifo; 
|   fi
| done
| 
| rm $fifo
| 
`----

This creates a fifo in /tmp and echos all the input from stdin to that
fifo.  When mplayer dies, the fifo is killed.

Then I wrote a simple script for finding the fifo name.  The fifos are
named <PID>.fifo, and I arbitrarily chose to return the smallest PID.

,----[ find-fifo.sh ]
| find /tmp -maxdepth 1 -regex "/tmp/[0-9]*\.fifo" -printf "%f\n"| sort -n| head -n 1
`----

I use this script in a script I call echo-pause.

,----[ echo-pause.sh ]
| 
| fifo=`/home/jesse/bin/find-fifo.sh`
| if [ -n "$fifo" ] && [ -e "/tmp/$fifo" ];
| then
|   echo -n " ">/tmp/$fifo;
| else
|   xmms -t;
| fi
`----

If there is an existing fifo for mplayer, then this file echos a space
into that fifo.  Otherwise, it calls xmms with -t (play/pause flag),
on the assumption that if I hit pause and there is no mplayer, then I
want to start/pause my cdplayer.

Finally, I edited .enlightenment/keybindings.cfg to include the
following.  For other window managers, you'll have to figure out what
to do yourself.

,----
|   __NEXT_ACTION
|     __KEY Pause
|     __EVENT __KEY_PRESS
|     __ACTION __A_EXEC /home/jesse/bin/echo-pause.sh
`----

So far, I see no negative side effects.  So far...

-- 
When I am grown to man's estate 
I shall be very proud and great,
and tell the other girls and boys
not to meddle with my toys.          --Robert Louis Stevenson 




More information about the MPlayer-users mailing list