/
listplayer.go
159 lines (129 loc) · 3.98 KB
/
listplayer.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0
package vlc
// #include "glue.h"
import "C"
// This player is meant for playlist playback.
// This is basically a wrapper for vlc.Player that takes care of playlist rotation.
type ListPlayer struct {
ptr *C.libvlc_media_list_player_t
}
// Release decreases the reference count of the instance and destroys it when it reaches zero.
func (this *ListPlayer) Release() (err error) {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_release(this.ptr)
return
}
// Events returns an Eventmanager for this player.
func (this *ListPlayer) Events() (*EventManager, error) {
if this.ptr == nil {
return nil, &VLCError{"ListPlayer is nil"}
}
if c := C.libvlc_media_list_player_event_manager(this.ptr); c != nil {
return NewEventManager(c), nil
}
return nil, checkError()
}
// Replace replaces the Player instance in this listplayer with a new one.
func (this *ListPlayer) Replace(p *Player) error {
if this.ptr == nil || p.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_set_media_player(this.ptr, p.ptr)
return checkError()
}
// Set sets the MediaList associated with this player.
func (this *ListPlayer) Set(l *MediaList) error {
if this.ptr == nil || l.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_set_media_list(this.ptr, l.ptr)
return checkError()
}
// Play plays the entries in the media list.
func (this *ListPlayer) Play() error {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_play(this.ptr)
return checkError()
}
// Pause pauses playback.
func (this *ListPlayer) Pause() error {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_pause(this.ptr)
return checkError()
}
// IsPlaying returns true if the player is currently playing.
func (this *ListPlayer) IsPlaying() (bool, error) {
if this.ptr == nil {
return false, &VLCError{"ListPlayer is nil"}
}
return C.libvlc_media_list_player_is_playing(this.ptr) != 0, checkError()
}
// State returns the current media state.
func (this *ListPlayer) State() (MediaState, error) {
if this.ptr == nil {
return 0, &VLCError{"ListPlayer is nil"}
}
return MediaState(C.libvlc_media_list_player_get_state(this.ptr)), checkError()
}
// PlayAt plays the entry at the given list index.
func (this *ListPlayer) PlayAt(pos int) error {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_play_item_at_index(this.ptr, C.int(pos))
return checkError()
}
// PlayItem plays the given entry.
//
// Note: The supplied Media must be part of this list.
func (this *ListPlayer) PlayItem(m *Media) error {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
if m.ptr == nil {
return &VLCError{"Media is nil"}
}
C.libvlc_media_list_player_play_item(this.ptr, m.ptr)
return checkError()
}
// Stop halts playback.
func (this *ListPlayer) Stop() error {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_stop(this.ptr)
return checkError()
}
// Next plays the next item in the list if applicable.
func (this *ListPlayer) Next() error {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_next(this.ptr)
return checkError()
}
// Prev plays the previous item in the list if applicable.
func (this *ListPlayer) Prev() error {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_previous(this.ptr)
return checkError()
}
// SetMode sets the current playback mode.
// Any of: PMDefault, PMLoop or PMRepeat.
func (this *ListPlayer) SetMode(pm PlaybackMode) error {
if this.ptr == nil {
return &VLCError{"ListPlayer is nil"}
}
C.libvlc_media_list_player_set_playback_mode(this.ptr, C.libvlc_playback_mode_t(pm))
return checkError()
}