forked from neosapience/cast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_linux.go
More file actions
37 lines (31 loc) · 846 Bytes
/
audio_linux.go
File metadata and controls
37 lines (31 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//go:build linux
package cmd
import (
"fmt"
"os/exec"
)
// playFile tries common Linux audio players in order of preference.
// Attempts: paplay (PulseAudio), aplay (ALSA), ffplay, mpv
func playFile(path, format string) error {
type player struct {
cmd string
args []string
}
players := []player{
{"paplay", []string{path}},
{"aplay", []string{path}},
{"ffplay", []string{"-nodisp", "-autoexit", path}},
{"mpv", []string{"--no-video", path}},
{"vlc", []string{"--intf", "dummy", "--play-and-exit", path}},
{"play", []string{path}},
}
for _, p := range players {
if _, err := exec.LookPath(p.cmd); err != nil {
continue
}
if err := exec.Command(p.cmd, p.args...).Run(); err == nil {
return nil
}
}
return fmt.Errorf("no audio player could play the file; try saving with --out and playing manually")
}