cmd/audio-player/looper: use a command line flag for choosing audio file path

This commit is contained in:
Scott 2020-02-28 16:28:02 +10:30
parent 8cbc7e700c
commit c5fb58e70c
1 changed files with 5 additions and 3 deletions

View File

@ -28,6 +28,7 @@ package main
import ( import (
"bytes" "bytes"
"flag"
"io" "io"
"os" "os"
"os/exec" "os/exec"
@ -38,8 +39,9 @@ import (
) )
func main() { func main() {
// Constants. // Command line flags.
const soundFile = "/home/pi/48khz.wav" var soundFilePtr = flag.String("path", "", "Location of sound file")
flag.Parse()
// Logging constants. // Logging constants.
const ( const (
@ -71,7 +73,7 @@ func main() {
numPlays++ numPlays++
log.Log(logger.Debug, "playing audio", "play number", numPlays) log.Log(logger.Debug, "playing audio", "play number", numPlays)
cmd := exec.Command(audioCmd, soundFile) cmd := exec.Command(audioCmd, *soundFilePtr)
var stdoutBuf, stderrBuf bytes.Buffer var stdoutBuf, stderrBuf bytes.Buffer
stdoutIn, _ := cmd.StdoutPipe() stdoutIn, _ := cmd.StdoutPipe()