You are not logged in.

#1 2016-02-02 16:39:53

Dave^
New Member
Registered: 2016-02-02
Posts: 3

[SOLVED] mplayer help (sorry!!)

Hi guys, I've just made it over from the #! forums, I was Dave6 on there due to the unallowed "^"... hehe!

So, to jump straight in, I'm trying to delete current playing track in mplayer, and found this solution:

http://superuser.com/questions/663247/i … in-mplayer

#/bin/bash
# rmplaying.sh
# only works when exactly 1 instance of mplayer is running
function playing {
PID=`pidof mplayer`
WHICH=`which mplayer`
if [ $PID ]; then
    lsof -p $PID | awk '{ if ($5=="REG" && $4!="mem" && $9)print $0 }' | grep -v "$WHICH" | grep -oP '\/.*'
fi
}

FILE="$(playing)"
echo "file: $FILE"
if [ "$FILE" ]; then
  rm "$FILE" && echo "Removed '$FILE'"
fi

I don't understand the WHICH variable, can someone assist please?

Thanks

Last edited by Dave^ (2016-02-02 19:55:09)

Offline

#2 2016-02-02 16:45:43

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] mplayer help (sorry!!)

WHICH is set to the full PATH of the external command 'mplayer'.
The backquotes cause a subshell to run the command 'which mplayer' and substitute the output of that command (the full path to mplayer, presumable /usr/bin/mplayer). The assignment then assigns that value to the variable WHICH.

Offline

#3 2016-02-02 17:15:08

Dave^
New Member
Registered: 2016-02-02
Posts: 3

Re: [SOLVED] mplayer help (sorry!!)

Brilliant, thanks. I shoulda guessed that.

So now, running the script "rmplaying.sh" manually works, but I can't get the shortcut within the mplayer terminal window to work.

/home/dave/rmplaying.sh: 4: /home/dave/rmplaying.sh: function: not found
/media/dave/filename.mp3
/home/dave/rmplaying.sh: 10: /home/dave/rmplaying.sh: Syntax error: "}" unexpected

Any pointers? (I hate "gimme answer" posts, but I'm stuck here!)

Offline

#4 2016-02-02 17:43:38

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: [SOLVED] mplayer help (sorry!!)

#/bin/bash

should be

#!/bin/bash

Offline

#5 2016-02-02 19:15:36

Dave^
New Member
Registered: 2016-02-02
Posts: 3

Re: [SOLVED] mplayer help (sorry!!)

Gawd, I looked at that and thought it didn't look right.

Proper n00b!  :8

Many thanks!

Offline

Board footer

Powered by FluxBB