Home Linux Community Forums Hardware Multimedia CLI mplayer Shuffle Music Directory & Info?

CLI mplayer Shuffle Music Directory & Info?

Link to this post 13 Apr 11

Does anyone here know how to configure mplayer in the command line to not only shuffle a directory of music but display the "now playing" info with each song change as well?

As of right now, I am able to shuffle my music directory with the following code:

find ~/Music/ | mplayer -shuffle -playlist -> /dev/null

I am running Debian GNU/Linux Squeeze on an x86_64 laptop.

My thanks to anyone who can help me figure this out!

Link to this post 13 Apr 11

I'm afraid your aproach has some drawbacks. I've made you a script for what you requested:

if [[ ${#} -lt 1 || ! -d ${1} ]]; then
echo "Calling failed, try with something like"
echo "${0} ~/Music"
exit 1

while IFS= read -r -d $'\0' file; do
a[i++]="$file" # or however you want to process each file
done < <(find "${1}" -name "*.mp3" -print0)
mplayer -shuffle "${a[@]}"

Place that in a file like shuffle_play

chmod +x shuffle_play
mv shuffle_play /usr/bin/ # as root!

Then give it a try with:

shuffle_play ~/Music

This will only play your mp3 files. If you need other file formats you can modify the script yourself or ask me to do it :)


Link to this post 14 Apr 11

Thank you very much! Your code worked perfectly :) I have a question, though. Where it states

done < <(find "${1}" -name "*.mp3" -print0)

Could I add a comma so that it would read
"*.ogg, .flac"

or something to that effect so it would include both ogg and FLAC formats?

Link to this post 14 Apr 11

It's a little trickier than that ;)

done < <(find "${1}" -name "*.mp3" -o -name "*.ogg" -o -name "*.flac" -print0)

That should do the trick!


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Linux Training / Board

/** BC-056 Ameex changes to add tracking code - 2016-01-22 **/ ?>