Advertisement
IssyPutchy

Resume playback from DSD waves

Apr 21st, 2020
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.31 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Credit to https://stackoverflow.com/questions/9639103/is-there-a-goto-statement-in-bash/31269848#31269848 for this goto style feature
  4.  
  5. jumpto ()
  6. {
  7.     label=$1
  8.     cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
  9.     eval "$cmd"
  10.     exit
  11. }
  12.  
  13. start=${1:-"start"}
  14.  
  15. jumpto $start
  16.  
  17. ##InotifyWait on our sound file and log modifications. DSD does not close the file when running and writes out, it appends.
  18.  
  19. start:
  20. while inotifywait -q -e modify snet.wav; do
  21.  
  22. # 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.
  23.  
  24.   SOXI=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 snet.wav)
  25.   sleep 1 # Buffer at least one second of audio
  26.   DAY=$(date +"%d-%m-%Y %T")
  27.    if [ "$SOXI" = "N/A" ]; then
  28.      echo "From start..."
  29.      NEWLENGTH=0
  30.    else
  31.      echo "Resuming from " $SOXI
  32.    fi
  33.   break
  34. done
  35.  
  36. # Use MPV to play the file, or resume from last place
  37.  
  38. mpv --start=$NEWLENGTH snet.wav
  39.  
  40. # After playing the file, check it's duration for resuming later
  41.  
  42. NEWLENGTH=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 snet.wav)
  43.  
  44. echo $DAY $NEWLENGTH
  45.  
  46. # Goto 10
  47. jumpto start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement