-
Notifications
You must be signed in to change notification settings - Fork 5
/
player.go
61 lines (51 loc) · 1.29 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"log"
vlc "github.com/adrg/libvlc-go/v3"
)
func main() {
// Initialize libVLC. Additional command line arguments can be passed in
// to libVLC by specifying them in the Init function.
if err := vlc.Init("--no-video", "--quiet"); err != nil {
log.Fatal(err)
}
defer vlc.Release()
// Create a new player.
player, err := vlc.NewPlayer()
if err != nil {
log.Fatal(err)
}
defer func() {
player.Stop()
player.Release()
}()
// Add a media file from path or from URL.
// Set player media from path:
// media, err := player.LoadMediaFromPath("localpath/test.mp4")
// Set player media from URL:
media, err := player.LoadMediaFromURL("http://stream-uk1.radioparadise.com/mp3-32")
if err != nil {
log.Fatal(err)
}
defer media.Release()
// Retrieve player event manager.
manager, err := player.EventManager()
if err != nil {
log.Fatal(err)
}
// Register the media end reached event with the event manager.
quit := make(chan struct{})
eventCallback := func(event vlc.Event, userData interface{}) {
close(quit)
}
eventID, err := manager.Attach(vlc.MediaPlayerEndReached, eventCallback, nil)
if err != nil {
log.Fatal(err)
}
defer manager.Detach(eventID)
// Start playing the media.
if err = player.Play(); err != nil {
log.Fatal(err)
}
<-quit
}