[MPlayer-users] Binding keys to mplayer?

Jesse F. Hughes jesse at phiwumbda.org
Wed Aug 25 15:55:46 CEST 2004


Torinthiel <torinthiel at megapolis.pl> writes:

> On Wed, Aug 25, 2004 at 02:26:10PM +0200, Jesse F. Hughes wrote:
>> ,----[ 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
>> | 
>> `----
>
> You know what? This is called active-waiting, and is BAD.
> But I don't see any better option.

Why is it bad?

>> 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
>> `----o
>
> I would consider putting find-fifo's content's into echo-pause. It saves
> one bash startup ;)

Yes, duh.  I'll do that.  Thanks.

>> 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.
>
> Well, something really good would be to pause everything on echo-pause.
> I mean detect ALL MPlayers, pause these that are running (No idea how).
> and pause xmms as well. This would be closer to 'incoming call, let's
> make everything quiet'

I thought about that, but the problem is that some of those mplayers
might *already* be paused, so it would un-pause them.  I often have
two or three mplayers running, with all but one paused (which makes my
fix admittedly less useful).

Oh, I see. Pause those that are *running*.  Gosh, that is a good idea.

But I don't know how to do it either.  I used to check fuser /dev/dsp,
but now that doesn't work since I use ALSA to mix sounds.  I'll bet
there's an alternative, though.  All one has to do is check to see
which processes are sending sound to the mixer (I don't need to pause
silent mplayers).

You suck.  Now I have to think about that.  And I was just starting to
get some work done, too.  Damn.

Anyway, thanks for the comments.  I'm not a BASH guru, obviously.  Now
if you can just elaborate on active-waiting, please.


-- 
Jesse Hughes
"She testified they had sex near the Oval Office, not in the famous
room itself, because that `wouldn't be appropriate, you know.'"
                                         -AP article




More information about the MPlayer-users mailing list