mirror of https://bitbucket.org/ausocean/av.git
cmd/audio-player/looper: wrote wrapper for lookPath calls to simplify code
This commit is contained in:
parent
d0646f73bc
commit
adbbd4d458
|
@ -5,6 +5,7 @@ DESCRIPTION
|
|||
AUTHORS
|
||||
Ella Pietraroia <ella@ausocean.org>
|
||||
Scott Barnard <scott@ausocean.org>
|
||||
Saxon Nelson-Milton <saxon@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
audio player is Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
|
||||
|
@ -29,6 +30,7 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -125,3 +127,11 @@ func main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkPath(cmd string, log *logger.Logger) {
|
||||
path, err := exec.LookPath(cmd)
|
||||
if err != nil {
|
||||
log.Log(logger.Fatal, fmt.Sprintf("couldn't find %s", cmd), "error", err)
|
||||
}
|
||||
log.Log(logger.Debug, fmt.Sprintf("found %s", cmd), "path", path)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ DESCRIPTION
|
|||
AUTHORS
|
||||
Ella Pietraroia <ella@ausocean.org>
|
||||
Scott Barnard <scott@ausocean.org>
|
||||
Saxon Nelson-Milton <saxon@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
|
||||
|
@ -29,7 +30,6 @@ LICENSE
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
|
@ -38,32 +38,25 @@ import (
|
|||
|
||||
const audioCmd = "play"
|
||||
|
||||
func initCommand(log *logger.Logger) {
|
||||
func initCommand(l *logger.Logger) {
|
||||
const (
|
||||
cardPath = "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
|
||||
retryDur = 5 * time.Second
|
||||
alsactl = "alsactl"
|
||||
)
|
||||
|
||||
// Make sure utility to set up sound card, alsactl, exists.
|
||||
path, err := exec.LookPath("alsactl")
|
||||
if err != nil {
|
||||
log.Log(logger.Fatal, "couldn't find alsactl", "error", err)
|
||||
}
|
||||
log.Log(logger.Debug, "alsactl found", "path", path)
|
||||
checkPath(alsactl, l)
|
||||
|
||||
// Set up sound card using alsactl.
|
||||
cmdInit := exec.Command("alsactl", "-f", cardPath, "restore")
|
||||
err = cmdInit.Run()
|
||||
cmdInit := exec.Command(alsactl, "-f", cardPath, "restore")
|
||||
err := cmdInit.Run()
|
||||
for err != nil {
|
||||
log.Log(logger.Warning, "alsactl run failed, retrying...", "error", err)
|
||||
l.Log(logger.Warning, "alsactl run failed, retrying...", "error", err)
|
||||
time.Sleep(retryDur)
|
||||
err = cmdInit.Run()
|
||||
}
|
||||
|
||||
// Make sure utility to play audio exists.
|
||||
path, err = exec.LookPath(audioCmd)
|
||||
if err != nil {
|
||||
log.Log(logger.Fatal, "couldn't find 'play' executable", "error", err)
|
||||
}
|
||||
log.Log(logger.Debug, fmt.Sprintf("%s found", audioCmd), "path", path)
|
||||
checkPath(audioCmd, l)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ DESCRIPTION
|
|||
AUTHORS
|
||||
Ella Pietraroia <ella@ausocean.org>
|
||||
Scott Barnard <scott@ausocean.org>
|
||||
Saxon Nelson-Milton <saxon@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
|
||||
|
@ -29,18 +30,9 @@ LICENSE
|
|||
package main
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"bitbucket.org/ausocean/utils/logger"
|
||||
)
|
||||
|
||||
const audioCmd = "omxplayer"
|
||||
|
||||
func initCommand(log *logger.Logger) {
|
||||
// Making sure that omxplayer command is on the pi.
|
||||
path, err := exec.LookPath("omxplayer")
|
||||
if err != nil {
|
||||
log.Log(logger.Fatal, "didn't find 'omxplayer' executable")
|
||||
}
|
||||
log.Log(logger.Debug, "'omxplayer' executable path", "path", path)
|
||||
}
|
||||
func initCommand(l *logger.Logger) { checkPath(audioCmd, l) }
|
||||
|
|
Loading…
Reference in New Issue