Control mplayer via Fvwm menus

I was quite discontent with the GUIs of media players out there – today I figured out how to control my mplayer from a menu. Here is how it works:

mplayer can read commands from a named pipe (fifo), that’s what I need. So first I created a fifo (this has to be done only once):

mkfifo /home/rbreu/.mplayer/pipe

Then I put the following line in my InitFunction:

+ I Exec exec mplayer -slave -idle -input file=/home/rbreu/.mplayer/pipe

This tells mplayer to read commands from the pipe and not to quit when it doesn’t have anything to play. So it will just sit around and wait for commands.

Now the menu: I put some basic functions (pause, next/previous song, +/- volume) into it, and via piperead all the subdirectories of my music directory. By selecting one of these directories, I want mplayer to play the directory.

[code]DestroyMenu MenuFvwmMusic
AddToMenu MenuFvwmMusic Music Title

  • “&Pause” Exec exec echo “pause” > /home/rbreu/.mplayer/pipe
  • “&Next” Exec exec echo “pt_step 1” > /home/rbreu/.mplayer/pipe
  • “P&revious” Exec exec echo “pt_step -1” > /home/rbreu/.mplayer/pipe
  • “Volume &+” Exec exec echo “volume +1 0” > /home/rbreu/.mplayer/pipe
  • “Volume &-” Exec exec echo “volume -1 0” > /home/rbreu/.mplayer/pipe
  • “” Nop
    Piperead “/home/rbreu/.fvwm/musicmenu.sh /usr/share/music”[/code]
    As you can see, I just write mplayer commands into the named pipe (see the mplayer documentation for mplayer commands). The script that browses my music directory looks like this:
    musicmenu.sh:

[code]#!/bin/sh

for f in $1/*; do
echo “+ $(basename $f) Exec exec /home/rbreu/.fvwm/playdir.sh $f”
done[/code]
For playing a directory, I have written another small script which writes a playlist with all the files in the directory. The playlist is then loaded into mplayer:
playdir.sh:

[code]#!/bin/sh

echo “” > /home/rbreu/.mplayer/playlist.txt

for f in $1/*; do
echo $f >> /home/rbreu/.mplayer/playlist.txt
done

echo “loadlist /home/rbreu/.mplayer/playlist.txt” > ~/.mplayer/pipe
[/code]

Now I have a simple but cool “FvwmMenu-Player”. :slight_smile: Ooh, and I haven’t even thought about keybindings 'n stuff… :wink:

nice scripts, but they didn’t work for me quite yet, because i got spaces in song names and folders… so i modified them a bit

musicmenu.sh

[code]#!/bin/sh

for f in $1/*; do
echo “+ “$(basename “$f”)” Exec /home/killasmurf/.fvwm/scripts/playdir.sh '”$f"’"
done[/code]

Still working to get 2nd script working like it should.

P.S. i know this is old threat, but it might help someone

Now you’re over-quoting. You only need to either quote “$f” or “$(…)” not both. Quoting “$1” also to avoid issues is a good thing also.

– Thomas Adam

I tired what you said and it didn’t work… (i tried several different ways, perhaps i did something wrong)
After i exec my script i get:

  • “Some artist and album name” Exec /home/killasmurf/.fvwm/scripts/playdir.sh “/Long path to songs”

Ok, after 1 and half day of learning sh, this is what i came up to resolve all my problems (and maybe someones else as well)

~/bin/rmwinshit.sh # - required for mkplaylists.sh this renames files/folders (to better, yet similar names), removes +x permissions
~/bin/mkplaylists.sh # - makes playlists in /home/share/music/playlst/, this removes *.jpg files (i don’t need them, if you need, then edit it), this will get rid of CD1/DISK1 etc subdirs, and rename files accordingly
~/.fvwm/Config/Scripts/musicmenu.sh # -generates menu for fvwm

1st and 2ns script can be launched with no arguments, but then ou need to cd to dir you wish to modify
or you can give that dir as argument without ending /

3rd script must be launched with path to playlist directory as argument

my $[FVWM_SCRIPTS] = $[FVWM_HOME]/Config/Scripts

DestroyMenu	MenuPlaylists
AddToMenu MenuPlaylists
Piperead "$[FVWM_SCRIPTS]/musicmenu.sh /home/share/music/playlst"

It takes about 5s for menus to be generated (for me, i got lots of music)
Use ~/bin/mkplaylists.sh to create playlists :slight_smile:


Also if you can optimise my code… let me know…
I just started learning sh…

Yes, you clearly did bugger something up. Note that the reason it takes a long time for you (i.e., 5 seconds) is due to the fact the damn thing is calculated each time – there’s no caching involved.

Oh, and having cast a very quick eye over your scripts, the “-delete” flag to find(1) is completely non-portable. You meant:

find . -name 'foo' -print0 | xargs -0 rm -fr

You seem to have a habit of opening up old threads. Very annoying.

– Thomas Adam

To make it clear it takes it 5secs when you start/restart/read all over menus…
It is as normal menu once it’s created… no delays

sorry for old topic think, but i think this one is very good topic… and i think this is finally solved for 100%

about portability buts etc… I only code sh for 2nd day :slight_smile:

EDIT

This gives me idea of outputing this to some file and then just reading this file. and when i need i can run script to regenerate that file… Why didn’t i thought of that before (well, i just finished this script as is few min ago :slight_smile: )

So?

Then you have learnt one thing from me if nothing else. I won’t appraise the rest of your scripts.

– Thomas Adam

DestroyMenu MenuPlaylists AddToMenu MenuPlaylists + "REGENERATE MENU step1" Exec exec $[FVWM_SCRIPTS]/musicmenu.sh /home/share/music/playlst > $[FVWM_USERDIR]/Cache/MenuPlayListsCached + "REGENARATE MENU step2" Read $[FVWM_USERDIR]/Cache/MenuPlayListsCached + "" Nop Read $[FVWM_USERDIR]/Cache/MenuPlayListsCached

musicmenu.sh is now modified
couldn’t figure out better way atm

you need now ~/.fvwm/Cache directory