Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell Raspbery Pi循环视频omxplayer_Shell_Video_Raspberry Pi - Fatal编程技术网

Shell Raspbery Pi循环视频omxplayer

Shell Raspbery Pi循环视频omxplayer,shell,video,raspberry-pi,Shell,Video,Raspberry Pi,我一直在做一个项目,在一个文件夹中播放所有视频。它工作得很好,但我需要根据输入更改视频路径,该输入随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

我一直在做一个项目,在一个文件夹中播放所有视频。它工作得很好,但我需要根据输入更改视频路径,该输入随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

一个好的答案将不胜感激,谢谢

将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