Welcome to the Linux Foundation Forum!

CLI mplayer Shuffle Music Directory & Info?


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!


  • marc
    marc Posts: 647
    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 :)

  • GrouchoMarxist
    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?
  • marc
    marc Posts: 647
    It's a little trickier than that ;)
    done < <(find "${1}" -name "*.mp3" -o -name "*.ogg" -o -name "*.flac" -print0)

    That should do the trick!



Upcoming Training