av/cmd/audio-player/looper/pi0.go

38 lines
992 B
Go
Raw Normal View History

// +build pi0
package main
import (
"os/exec"
"time"
"bitbucket.org/ausocean/utils/logger"
)
const audioCmd = "play"
func initCommand(log *logger.Logger) {
const soundcardPath = "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
const sleepDur = 1 * time.Second
// alsactl is a command that ensures the sound will be played through the correct soundcard.
path, err := exec.LookPath("alsactl")
if err != nil {
log.Log(logger.Fatal, "didn't find 'alsactl' executable")
}
log.Log(logger.Debug, "'alsactl' executable path", "path", path)
2020-03-02 05:03:01 +03:00
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
for cmdInit.Run() != nil {
log.Log(logger.Warning, "cmd.Run() for 'alsactl' failed", "error", err.Error())
time.Sleep(sleepDur)
}
// Making sure that play command is on the pi.
path, err = exec.LookPath(audioCmd)
if err != nil {
log.Log(logger.Fatal, "didn't find 'play' executable")
}
log.Log(logger.Debug, "'play' executable path", "path", path)
}