-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvolume.go
More file actions
43 lines (38 loc) · 1020 Bytes
/
volume.go
File metadata and controls
43 lines (38 loc) · 1020 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
38
39
40
41
42
43
package termux
import (
"bytes"
"encoding/json"
)
// AudioStreamState represents the volume info of an audio stream
type AudioStreamState struct {
Name string `json:"stream"`
Volume int `json:"volume"`
MaxVolume int `json:"max_volume"`
}
// AudioStreams acquires all audio stream volume info from the device
func AudioStreams() ([]AudioStreamState, error) {
buf := bytes.NewBuffer([]byte{})
if err := exec(nil, buf, "Volume", nil, ""); err != nil {
return nil, err
}
res := buf.Bytes()
if err := checkErr(res); res != nil {
return nil, err
}
l := make([]AudioStreamState, 0)
if err := json.Unmarshal(res, l); err != nil {
return nil, err
}
return l, nil
}
// AudioStreamVolume sets the volume of a given audio stream name
func AudioStreamVolume(name string, volume int) error {
buf := bytes.NewBuffer([]byte{})
if err := exec(nil, buf, "Volume", map[string]interface{}{
"stream": name,
"volume": volume,
}, ""); err != nil {
return err
}
return checkErr(buf.Bytes())
}