-
Notifications
You must be signed in to change notification settings - Fork 8
/
maudio.go
70 lines (60 loc) · 1.78 KB
/
maudio.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package webostv
import (
"github.com/mitchellh/mapstructure"
)
func (tv *Tv) AudioGetMute() (mute bool, err error) {
// "payload":{"mute":false,"returnValue":true}
var resp struct {
Mute bool
}
err = tv.RequestResponseParam("ssap://audio/getMute", nil, &resp)
return resp.Mute, err
}
type AudioStatus struct {
Scenario string
Volume int
Mute bool
}
func (tv *Tv) AudioGetStatus() (as AudioStatus, err error) {
// "payload":{"returnValue":true,"scenario":"mastervolume_tv_speaker","volume":9,"mute":false}
err = tv.RequestResponseParam("ssap://audio/getStatus", nil, &as)
return as, err
}
func (tv *Tv) AudioMonitorStatus(process func(as AudioStatus) error, quit <-chan struct{}) error {
return tv.MonitorStatus("ssap://audio/getStatus", nil, func(payload Payload) (err error) {
var as AudioStatus
err = mapstructure.Decode(payload, &as)
if err == nil {
err = process(as)
}
return err
}, quit)
}
func (tv *Tv) AudioGetVolume() (scenario string, volume int, muted bool, err error) {
// "payload":{"returnValue":true,"scenario":"mastervolume_tv_speaker","volume":9,"muted":false}
var resp struct {
Scenario string
Volume int
Muted bool
}
err = tv.RequestResponseParam("ssap://audio/getVolume", nil, &resp)
return resp.Scenario, resp.Volume, resp.Muted, err
}
func (tv *Tv) AudioSetMute(mute bool) (err error) {
_, err = tv.Request("ssap://audio/setMute",
Payload{"mute": mute})
return err
}
func (tv *Tv) AudioSetVolume(volume int) (err error) {
_, err = tv.Request("ssap://audio/setVolume",
Payload{"volume": volume})
return err
}
func (tv *Tv) AudioVolumeDown() (err error) {
_, err = tv.Request("ssap://audio/volumeDown", nil)
return err
}
func (tv *Tv) AudioVolumeUp() (err error) {
_, err = tv.Request("ssap://audio/volumeUp", nil)
return err
}