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
“” 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
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
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.
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
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 )