Skip to content

Instantly share code, notes, and snippets.

@mazgi
Last active August 29, 2015 14:01
Show Gist options
  • Save mazgi/1d1731ca6b47668bb7fa to your computer and use it in GitHub Desktop.
Save mazgi/1d1731ca6b47668bb7fa to your computer and use it in GitHub Desktop.
OMXPlayer auto start script
#!/bin/bash
set -e
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "${READLINK}" ]; then
echo "[ERROR] Connot find readlink" >& 2
exit 1
fi
PLAYLIST_PATH="/media/playlist.txt"
if [ ! -f "${PLAYLIST_PATH}" ]; then
echo "[ERROR] Connot find playlist.txt" >& 2
exit 1
fi
CONTROL_PATH="/media/control.txt"
PLAYER_CMD="/usr/bin/omxplayer --blank"
function stop() {
reason="${1}"
run=false
if [[ ${player_pid} -gt 0 ]]; then
kill ${player_pid}
wait ${player_pid}
fi
echo "Stop movie play. reason: ${reason}."
run=false
exit 0
}
trap 'stop "signal recieved"' TERM
run=true; while ${run}
do
while read movie
do
if [ -f ${CONTROL_PATH} ]; then
cmd=$(head -1 ${CONTROL_PATH} | tr -d "[:blank:]" | tr '[a-z]' '[A-Z]')
echo "$(date): command recieved" > ${CONTROL_PATH}
case ${cmd} in
"STOP" )
stop '[stop] command recieved'
break
;;
esac
fi
movie_path="$(dirname $(${READLINK} -f "${PLAYLIST_PATH}"))/${movie}"
if [ -f "${movie_path}" ]; then
${PLAYER_CMD} "${movie_path}" &
player_pid=$!
wait
unset player_pid
fi
done < ${PLAYLIST_PATH}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment