-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclient_test.go
More file actions
89 lines (76 loc) · 1.78 KB
/
Copy pathclient_test.go
File metadata and controls
89 lines (76 loc) · 1.78 KB
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
81
82
83
84
85
86
87
88
89
package mpv_test
import (
"fmt"
"testing"
"github.com/gen2brain/go-mpv"
)
func TestMPV(t *testing.T) {
m := mpv.New()
defer m.TerminateDestroy()
err := m.RequestLogMessages("v")
if err != nil {
t.Errorf("RequestLogMessages: %v", err)
}
err = m.ObserveProperty(0, "pause", mpv.FormatFlag)
if err != nil {
t.Errorf("ObserveProperty: %v", err)
}
err = m.SetPropertyString("vo", "null")
if err != nil {
t.Errorf("SetPropertyString: %v", err)
}
err = m.SetOptionString("ao", "null")
if err != nil {
t.Errorf("SetOptionString: %v", err)
}
err = m.SetOption("cache", mpv.FormatFlag, true)
if err != nil {
t.Errorf("SetOption: %v", err)
}
err = m.Initialize()
if err != nil {
t.Errorf("Initialize: %v", err)
}
err = m.Command([]string{"loadfile", "testdata/test.mpg"})
if err != nil {
t.Errorf("Command: %v", err)
}
loop:
for {
e := m.WaitEvent(10000)
switch e.EventID {
case mpv.EventPropertyChange:
prop := e.Property()
value := prop.Data.(int)
fmt.Println("property:", prop.Name, value)
case mpv.EventFileLoaded:
p, err := m.GetProperty("media-title", mpv.FormatString)
if err != nil {
t.Errorf("GetProperty: %v", err)
}
fmt.Println("title:", p.(string))
case mpv.EventLogMsg:
msg := e.LogMessage()
fmt.Println("message:", msg.Text)
case mpv.EventStart:
sf := e.StartFile()
fmt.Println("start:", sf.EntryID)
case mpv.EventEnd:
ef := e.EndFile()
fmt.Println("end:", ef.EntryID, ef.Reason)
if ef.Reason == mpv.EndFileEOF {
break loop
} else if ef.Reason == mpv.EndFileError {
t.Errorf("EventEnd: %v", err)
}
case mpv.EventShutdown:
fmt.Println("shutdown:", e.EventID)
break loop
default:
fmt.Println("event:", e.EventID)
}
if e.Error != nil {
fmt.Println("error:", e.Error)
}
}
}