Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Credit to https://stackoverflow.com/questions/9639103/is-there-a-goto-statement-in-bash/31269848#31269848 for this goto style feature
- jumpto ()
- {
- label=$1
- cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
- eval "$cmd"
- exit
- }
- start=${1:-"start"}
- jumpto $start
- ##InotifyWait on our sound file and log modifications. DSD does not close the file when running and writes out, it appends.
- start:
- while inotifywait -q -e modify snet.wav; do
- # Use ffprobe instead of soxi, more reliable. This is to check if the file is new or contains audio already. If new, play from start, if not, the variable to end of script will be resume point.
- SOXI=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 snet.wav)
- sleep 1 # Buffer at least one second of audio
- DAY=$(date +"%d-%m-%Y %T")
- if [ "$SOXI" = "N/A" ]; then
- echo "From start..."
- NEWLENGTH=0
- else
- echo "Resuming from " $SOXI
- fi
- break
- done
- # Use MPV to play the file, or resume from last place
- mpv --start=$NEWLENGTH snet.wav
- # After playing the file, check it's duration for resuming later
- NEWLENGTH=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 snet.wav)
- echo $DAY $NEWLENGTH
- # Goto 10
- jumpto start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement