Wednesday, July 23, 2008

Random, shuffled, endless playlists with mplayer and sh

It's portable and easy. There's no need to do shell / environment specific stuff, mess with arrays in shell scripts or worry about spaces in filenames: this works in any semi-POSIX compliant environment that can run mplayer.

while `true`; do find "$1" -name \*.mp3 | while read filename; do echo $filename >> /tmp/pls.$$; done; mplayer -shuffle -playlist /tmp/pls.$$; rm /tmp/pls.$$; done

I have this plopped in ~/bin/play and run play ~/mp3 which works well for me. You could also do 2>&1 >/dev/null & or >& /dev/null & (for sh/csh like shells respectively) to kill output and background the process if you want.

Have fun :)