mhollander38
mhollander38

Reputation: 775

Bash Script to Loop Through All Videos in a Folder on Raspbian Wheezy

I have the following bash script courtesy of this post:

#!/bin/sh

# get rid of the cursor so we don't see it when videos are running
setterm -cursor off

# set here the path to the directory containing your videos
VIDEOPATH="/mnt/storage/videos" 

# you can normally leave this alone
SERVICE="omxplayer"

# now for our infinite loop!
while true; do
    if ps ax | grep -v grep | grep $SERVICE > /dev/null
    then
        sleep 1;
    else
        for entry in $VIDEOPATH/*
        do
            clear
            omxplayer $entry > /dev/null
        done
    fi
 done

I have changed the call to omxplayer to full screen and output the sound so:

omxplayer -r -o hdmi $entry > /dev/null

But even before that change to my preferred settings the script only seems to play the first video in the folder which it loops over endlessly. I have checked the permission on the videos and they are all the same owned by the user who runs the script.

Upvotes: 1

Views: 5029

Answers (1)

amit_g
amit_g

Reputation: 31250

That script is wrong. I have made some updates to it. See if that works for you

#!/bin/sh

# get rid of the cursor so we don't see it when videos are running
setterm -cursor off

# set here the path to the directory containing your videos
VIDEOPATH="/mnt/storage/videos" 

# you can normally leave this alone
SERVICE="omxplayer"

for entry in $VIDEOPATH/*
do
    clear
    $SERVICE $entry > /dev/null

    while ps ax | grep -v grep | grep $SERVICE > /dev/null
    do
        sleep 5;
    done
done

Upvotes: 1

Related Questions