forked from CyCoreSystems/ari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.go
38 lines (30 loc) · 874 Bytes
/
player.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
package testutils
import "github.com/CyCoreSystems/ari"
// A PlayerPair is the pair of results returned from a mock Play request
type PlayerPair struct {
Handle *ari.PlaybackHandle
Err error
}
// Player is the test player that can be primed with sample data
type Player struct {
Next chan struct{}
results []PlayerPair
}
// NewPlayer creates a new player
func NewPlayer() *Player {
return &Player{
Next: make(chan struct{}, 10),
}
}
// Append appends the given Play results
func (p *Player) Append(h *ari.PlaybackHandle, err error) {
p.results = append(p.results, PlayerPair{h, err})
}
// Play pops the top results and returns them, as well as triggering player.Next
func (p *Player) Play(mediaURI string) (h *ari.PlaybackHandle, err error) {
h = p.results[0].Handle
err = p.results[0].Err
p.results = p.results[1:]
p.Next <- struct{}{}
return
}