Mplayer uses a simple kind of playlist: a text file with the path and name of each file to be played. The path to the new file is relative to the location of the playlist file itself. So, you can do something like this:
find -maxdepth 1 -type f -name \*.\* > playlist
This will find all the files in the current directory that have a “.” character in it, and put the results into playlist (a text file) — i.e., it will find all files with some kind of extension, and exclude directory names with a period in them. This works well if the only type of files with extensions are audio files. If you want to search deeper down directory levels, just increase the maxdepth value, or leave out the maxdepth parameter altogether to search recursively.
The “>” operator replaces whatever text was inside the “playlist” file with the output of the previous command (here, the find command with all our options). If you just wanted to append the results to an existing playlist file, you could just use “>>” instead of “>”.
To play the playlist, just do:
mplayer -playlist playlist
…where “playlist” is the file with all the songs in it. Be sure to include the full path to the playlist if you are currently not inside the same directory. To make the entire playlist loop forever, type:
mplayer -playlist playlist -loop 0
and it will loop the entire playlist forever. Unfortunately, putting the “loop=0″ info in my ~/.mplayer/config file makes mplayer read that paramter first, and thus, only repeat the first file in my playlist forever. There seems to be no workaroud to this, except manually appending the loop paramter after the playlist parameter, as shown above.
More info here.
UPDATE November 12, 2009: I discovered a simple hack around the above mentioned problem about trying to loop the entire playlist. The solution is to remove the “loop=0″ line from your ~/.mplayer/config, and instead make use of shell aliases. I use zsh, and this is what I have in my ~/.zshrc (the second alias is the key):
alias m='mplayer -loop 0'
alias mp='mplayer -loop 0 -playlist'
Now, to play any single file infinitely, simply use “m [file]“. To infinitely loop an entire playlist, simply do “mp [playlist]“. You can “>” and “<” hotkeys to move around the playlist.