Category Archives: mplayer bash media audio folder directory

Bash script that plays audio in folder

#!/bin/bash

MPLAYER=mplayer
LIST_FILES_CMD=”ls”

DEPTH=5
TRUE=0
FALSE=1

function play {
    $MPLAYER “$1”
    RES=$?
    echo “Player exit status: $RES”
    return $RES
}

function play_folder {
    echo “Playing folder:”
    echo “”$1″”
    echo “Depth $2”
    FILES=`$LIST_FILES_CMD`
    IFS=$’n’
    for F in $FILES; do
        if [ -d “$F” ]; then
        echo “Going to subfolder “$F””
        if [ $2 -ge  $DEPTH ]; then
        echo “Depth level exceeds $DEPTH, exiting…”
        return $FALSE
        else
        CUR_DEPTH=$(( $2 + 1 ))
        pushd “$F” > /dev/null
        if ( ! play_folder “$F” $CUR_DEPTH ); then
            return $FALSE
        fi
        popd > /dev/null
        fi
        else
        echo “Playing “$F””
        if ( ! play “$F” ); then
        echo “$MPLAYER returns non-success result, exiting…”
        return $FALSE
        fi
        fi
    done
    echo “All files played in “$1″.”
    return $TRUE
}

play_folder “$PWD” 0

Please follow and like us: