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

41 lines
957 B
Go

// +build pi0
package main
import (
"log"
"os/exec"
"time"
)
const audioCmd = "play"
func initCommand() {
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.Fatalf("fatal: didn't find 'alsactl' executable\n")
}
log.Printf("debug: 'alsactl' executable is in '%s'\n", path)
for {
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
err := cmdInit.Run()
if err == nil {
break
}
log.Printf("fatal(ish): cmd.Run() for 'alsactl' failed with '%s'\n", err)
time.Sleep(sleepDur)
}
// Making sure that play command is on the pi.
path, err = exec.LookPath(audioCmd)
if err != nil {
log.Fatalf("fatal: didn't find 'play' executable\n")
}
log.Printf("debug: 'play' executable is in '%s'\n", path)
}