forked from henrym/go-vlc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
medialist.go
181 lines (150 loc) · 4.52 KB
/
medialist.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// 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 <stdlib.h>
//#include <vlc/vlc.h>
import "C"
import (
"syscall"
)
// Maintains a list of Media items.
type MediaList struct {
ptr *C.libvlc_media_list_t
}
// Retain increments the reference count of this MediaList instance.
func (this *MediaList) Retain() error {
if this.ptr == nil {
return syscall.EINVAL
}
C.libvlc_media_list_retain(this.ptr)
return checkError()
}
// Release cleans up any memory used by this list and decrements the
// reference counter for the Media instance this came from.
func (this *MediaList) Release() error {
if this.ptr == nil {
return syscall.EINVAL
}
C.libvlc_media_list_release(this.ptr)
this.ptr = nil
return checkError()
}
// Set associates a media instance with this media list.
// If another media instance was present it will be released.
//
// Note: MediaList.Lock() should NOT be held upon entering this function.
func (this *MediaList) Set(m *Media) error {
if this.ptr == nil || m.ptr == nil {
return syscall.EINVAL
}
C.libvlc_media_list_set_media(this.ptr, m.ptr)
return checkError()
}
// Get returns a media instance from this list.
// This action will increase the reference count on the media instance.
//
// Note: MediaList.Lock() should NOT be held upon entering this function.
func (this *MediaList) Get() (*Media, error) {
if this.ptr == nil {
return nil, syscall.EINVAL
}
if c := C.libvlc_media_list_media(this.ptr); c != nil {
return &Media{c}, nil
}
return nil, checkError()
}
// Add adds a media instance to this list.
//
// Note: MediaList.Lock() SHOULD be held upon entering this function.
func (this *MediaList) Add(m *Media) error {
if this.ptr == nil || m.ptr == nil {
return syscall.EINVAL
}
C.libvlc_media_list_add_media(this.ptr, m.ptr)
return checkError()
}
// Insert adds a media instance to the list at the given position.
//
// Note: MediaList.Lock() SHOULD be held upon entering this function.
func (this *MediaList) Insert(m *Media, pos int) error {
if this.ptr == nil || m.ptr == nil {
return syscall.EINVAL
}
C.libvlc_media_list_insert_media(this.ptr, m.ptr, C.int(pos))
return checkError()
}
// Remove removes a media instance at the given position from the list.
//
// Note: MediaList.Lock() SHOULD be held upon entering this function.
func (this *MediaList) Remove(pos int) error {
if this.ptr == nil {
return syscall.EINVAL
}
C.libvlc_media_list_remove_index(this.ptr, C.int(pos))
return checkError()
}
// Count returns the number if items in the list.
//
// Note: MediaList.Lock() SHOULD be held upon entering this function.
func (this *MediaList) Count() (int, error) {
if this.ptr == nil {
return 0, syscall.EINVAL
}
return int(C.libvlc_media_list_count(this.ptr)), checkError()
}
// At returns the media at the given list position.
// This action will increase the reference count on the media instance.
//
// Note: MediaList.Lock() SHOULD be held upon entering this function.
func (this *MediaList) At(pos int) (*Media, error) {
if this.ptr == nil {
return nil, syscall.EINVAL
}
if c := C.libvlc_media_list_item_at_index(this.ptr, C.int(pos)); c != nil {
return &Media{c}, nil
}
return nil, checkError()
}
// Index returns the position of the given media in the list.
//
// Note: MediaList.Lock() SHOULD be held upon entering this function.
func (this *MediaList) Index(m *Media) (int, error) {
if this.ptr == nil || m.ptr == nil {
return 0, syscall.EINVAL
}
return int(C.libvlc_media_list_index_of_item(this.ptr, m.ptr)), checkError()
}
// IsReadOnly returns true if this list is readonly for a user.
func (this *MediaList) IsReadOnly() (bool, error) {
if this.ptr == nil {
return false, syscall.EINVAL
}
return C.libvlc_media_list_is_readonly(this.ptr) == 0, checkError()
}
// Lock gets a lock on the list items.
func (this *MediaList) Lock() error {
if this.ptr == nil {
return syscall.EINVAL
}
C.libvlc_media_list_lock(this.ptr)
return checkError()
}
// Unlock removes a lock on the list items.
func (this *MediaList) Unlock() error {
if this.ptr == nil {
return syscall.EINVAL
}
C.libvlc_media_list_unlock(this.ptr)
return checkError()
}
// Events returns an Eventmanager for this list.
func (this *MediaList) Events() (*EventManager, error) {
if this.ptr == nil {
return nil, syscall.EINVAL
}
if c := C.libvlc_media_list_event_manager(this.ptr); c != nil {
return NewEventManager(c), nil
}
return nil, checkError()
}