-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.go
68 lines (56 loc) · 1.42 KB
/
controls.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
package kodicli
var (
controlPlayPause = "Player.PlayPause"
controlStop = "Player.Stop"
)
// playPauseArgs structure contains informations for a Player.PlayPause RPC request
type playPauseArgs struct {
PlayerID int `json:"playerid"`
}
// SendPlayPauseRequest sends a request to Play|Pause the player of
// the kodi configured in the RPC client
func (k *KodiRPCClient) SendPlayPauseRequest() (*int, error) {
req := RPCRequest{
ID: k.nextID,
Method: controlPlayPause,
Args: playPauseArgs{PlayerID: 1},
JSONRPC: jsonRPCVersion,
}
res, err := k.doRequest(&req)
if err != nil {
return nil, err
}
resMap, ok := res.Result.(map[string]interface{})
if !ok {
return nil, ErrUnableToParseResponse
}
if s, ok := resMap["speed"]; ok {
if f64, ok := s.(float64); ok {
speed := int(f64)
return &speed, nil
}
}
return nil, ErrUnexpectedResponse
}
// stopArgs structure contains informations for a Player.Stop RPC request
type stopArgs struct {
PlayerID int `json:"playerid"`
}
// SendStopRequest sends a request to Stop the player of
// the kodi configured in the RPC Client
func (k *KodiRPCClient) SendStopRequest() error {
req := RPCRequest{
ID: k.nextID,
Method: controlStop,
Args: stopArgs{PlayerID: 1},
JSONRPC: jsonRPCVersion,
}
res, err := k.doRequest(&req)
if err != nil {
return err
}
if !checkResultOk(res.Result) {
return ErrUnableToParseResponse
}
return nil
}