2014-04-23 135 views
0

我一直在一個項目中播放一個文件夾中的所有視頻。它工作的很好,但我需要視頻路徑根據定期更改的輸入更改CRON。我希望它在輸入更改後立即更改視頻通道,但不要直到當前視頻結束,但不播放當前視頻通道中的其餘視頻。Raspbery Pi - 循環視頻omxplayer

這裏是文件夾中播放所有視頻代碼:

#!/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 

一個很好的答案將非常感激,謝謝!

回答

0

將for循環放入函數中,如果輸入已更改,則遞歸調用它。您不需要while循環,因爲腳本只會在omxplayer完成播放視頻後繼續運行

#!/bin/sh 

VIDEOPATH="/mnt/storage/videos" 
SERVICE="omxplayer" 

function playvideos { 

    for entry in $1/* 
    do 
    clear 
    $2 $entry > /dev/null 

    if [ $input_has_changed ] 
    then 
     # get new video path here 
     playvideos $NEW_VIDEO_PATH $2 
     break 
    fi 
    done 
} 

playvideos $VIDEOPATH $SERVICE