我一直致力于一个项目来播放文件夹中的所有视频。它工作正常,但我需要视频路径根据CRON定期更改的输入进行更改。我想让它在输入改变后立即改变视频,但不是直到当前视频结束,而是在当前视频中没有播放剩余的视频。
以下是播放文件夹中所有视频的代码:
#!/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 :(得分: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