-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppVolume.go
80 lines (73 loc) · 1.59 KB
/
AppVolume.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
71
72
73
74
75
76
77
78
79
80
package winAudioApi
import (
"fmt"
"github.com/nasooory/go-winAudioApi/audioSession"
)
func FindApp(es *EndpointSession, appName string) ([]*audioSession.AppAudio, error) {
retVal := []*audioSession.AppAudio{}
if len(es.Apps) == 0 {
return nil, fmt.Errorf("app array on endpoint session length is 0")
}
for _, app := range es.Apps {
if app.AppName == appName {
retVal = append(retVal, app)
}
}
return retVal, nil
}
func (es *EndpointSession) SetAppVolume(name string, volume int) (bool, error) {
apps, err := FindApp(es, name)
if err != nil {
return false, err
}
for _, app := range apps {
_, err := app.SetVolume(volume)
if err != nil {
return false, err
}
}
return true, nil
}
func (es *EndpointSession) GetAppVolume(name string) ([]int, error) {
apps, err := FindApp(es, name)
if err != nil {
return nil, err
}
vols := []int{}
for _, app := range apps {
vol, err := app.GetVolume()
if err != nil {
return nil, err
}
vols = append(vols, vol)
}
return vols, nil
}
func (es *EndpointSession) SetAppMuteState(name string, state bool) (bool, error) {
apps, err := FindApp(es, name)
if err != nil {
return false, err
}
for _, app := range apps {
_, err := app.SetMuteState(state)
if err != nil {
return false, err
}
}
return true, nil
}
func (es *EndpointSession) GetAppMuteState(name string) ([]bool, error) {
apps, err := FindApp(es, name)
if err != nil {
return nil, err
}
vols := []bool{}
for _, app := range apps {
vol, err := app.GetMuteState()
if err != nil {
return nil, err
}
vols = append(vols, vol)
}
return vols, nil
}