title: Raspbery Pi - Looping video omxplayer
body: <p>I have been working on a project to play all videos in a folder. It works just fine, but I need the video path to change based on input that change periodically with CRON. I want it to change the video path as soon as the input change, but not until the current video ended, but without playing the rest of the video in the current video path.</p>
  <p>Here is the code to play all video in the folder:</p>
  <pre><code>#!/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=&quot;/mnt/storage/videos&quot; 
  
  # you can normally leave this alone
  SERVICE=&quot;omxplayer&quot;
  
  for entry in $VIDEOPATH/*
      do
          clear
      $SERVICE $entry &gt; /dev/null
  
      while ps ax | grep -v grep | grep $SERVICE &gt; /dev/null
      do
          sleep 5;
      done
  done
  </code></pre>