2 """Create a new Instance instance.
4 It may take as parameter either:
6 - a list of strings as first parameters
7 - the parameters given as the constructor parameters (must be strings)
8 - a MediaControl instance
13 elif p and isinstance(p[0], (int, long)):
14 # instance creation from ctypes
16 o._as_parameter_=ctypes.c_void_p(p[0])
18 elif len(p) == 1 and isinstance(p[0], basestring):
19 # Only 1 string parameter: should be a parameter line
21 elif len(p) == 1 and isinstance(p[0], (tuple, list)):
24 if p and isinstance(p[0], MediaControl):
25 return p[0].get_instance()
27 if not p and detected_plugin_path is not None:
28 # No parameters passed. Under win32 and MacOS, specify
29 # the detected_plugin_path if present.
30 p=[ 'vlc', '--plugin-path='+ detected_plugin_path ]
32 return libvlc_new(len(p), p, e)
34 def media_player_new(self, uri=None):
35 """Create a new Media Player object.
37 @param uri: an optional URI to play in the player.
40 p=libvlc_media_player_new(self, e)
42 p.set_media(self.media_new(uri))
46 def media_list_player_new(self):
47 """Create an empty Media Player object
50 p=libvlc_media_list_player_new(self, e)
54 def media_new(self, mrl, *options):
55 """Create an empty Media Player object
57 Options can be specified as supplementary string parameters, e.g.
58 m=i.media_new('foo.avi', 'sub-filter=marq{marquee=Hello}', 'vout-filter=invert')
61 m=libvlc_media_new(self, mrl, e)
63 libvlc_media_add_option(m, o, e)
67 """Create a new MediaControl instance
69 It may take as parameter either:
71 - a list of strings as first parameters
72 - the parameters given as the constructor parameters (must be strings)
78 elif p and isinstance(p[0], (int, long)):
79 # instance creation from ctypes
81 o._as_parameter_=ctypes.c_void_p(p[0])
83 elif len(p) == 1 and isinstance(p[0], basestring):
84 # Only 1 string parameter: should be a parameter line
86 elif len(p) == 1 and isinstance(p[0], (tuple, list)):
89 if p and isinstance(p[0], Instance):
90 e=MediaControlException()
91 return mediacontrol_new_from_instance(p[0], e)
93 if not p and detected_plugin_path is not None:
94 # No parameters passed. Under win32 and MacOS, specify
95 # the detected_plugin_path if present.
96 p=[ 'vlc', '--plugin-path='+ detected_plugin_path ]
97 e=MediaControlException()
98 return mediacontrol_new(len(p), p, e)
100 def get_media_position(self, origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime):
101 e=MediaControlException()
102 p=mediacontrol_get_media_position(self, origin, key, e)
108 def set_media_position(self, pos):
109 """Set the media position.
111 @param pos: a MediaControlPosition or an integer (in ms)
113 if not isinstance(pos, MediaControlPosition):
114 pos=MediaControlPosition(long(pos))
115 e=MediaControlException()
116 mediacontrol_set_media_position(self, pos, e)
118 def start(self, pos=0):
119 """Start the player at the given position.
121 @param pos: a MediaControlPosition or an integer (in ms)
123 if not isinstance(pos, MediaControlPosition):
124 pos=MediaControlPosition(long(pos))
125 e=MediaControlException()
126 mediacontrol_start(self, pos, e)
128 def snapshot(self, pos=0):
131 Note: the position parameter is not properly implemented. For
132 the moment, the only valid position is the 0-relative position
133 (i.e. the current position).
135 @param pos: a MediaControlPosition or an integer (in ms)
137 if not isinstance(pos, MediaControlPosition):
138 pos=MediaControlPosition(long(pos))
139 e=MediaControlException()
140 p=mediacontrol_snapshot(self, pos, e)
143 # FIXME: there is a bug in the current mediacontrol_snapshot
144 # implementation, which sets an incorrect date.
146 snap.date=self.get_media_position().value
151 def display_text(self, message='', begin=0, end=1000):
152 """Display a caption between begin and end positions.
154 @param message: the caption to display
155 @param begin: the begin position
156 @param end: the end position
158 if not isinstance(begin, MediaControlPosition):
159 begin=self.value2position(begin)
160 if not isinstance(end, MediaControlPosition):
161 end=self.value2position(end)
162 e=MediaControlException()
163 mediacontrol_display_text(self, message, begin, end, e)
165 def get_stream_information(self, key=PositionKey.MediaTime):
166 """Return information about the stream.
168 e=MediaControlException()
169 return mediacontrol_get_stream_information(self, key, e).contents
172 def add_options(self, *list_of_options):
173 """Add a list of options to the media.
175 Options must be written without the double-dash, e.g.:
176 m.add_options('sub-filter=marq@test{marquee=Hello}', 'video-filter=invert')
178 Note that you also can directly pass these options in the Instance.media_new method:
179 m=instance.media_new( 'foo.avi', 'sub-filter=marq@test{marquee=Hello}', 'video-filter=invert')
181 for o in list_of_options:
185 """Create a new MediaPlayer instance.
187 It may take as parameter either:
188 - a string (media URI). In this case, a vlc.Instance will be created.
191 def __new__(cls, *p):
194 elif p and isinstance(p[0], (int, long)):
195 # instance creation from ctypes
196 o=object.__new__(cls)
197 o._as_parameter_=ctypes.c_void_p(p[0])
200 if p and isinstance(p[0], Instance):
201 return p[0].media_player_new()
204 o=i.media_player_new()
206 o.set_media(i.media_new(p[0]))
209 def get_instance(self):
210 """Return the associated vlc.Instance.
212 return self._instance
214 class MediaListPlayer:
215 """Create a new MediaPlayer instance.
217 It may take as parameter either:
221 def __new__(cls, *p):
224 elif p and isinstance(p[0], (int, long)):
225 # instance creation from ctypes
226 o=object.__new__(cls)
227 o._as_parameter_=ctypes.c_void_p(p[0])
229 elif len(p) == 1 and isinstance(p[0], (tuple, list)):
232 if p and isinstance(p[0], Instance):
233 return p[0].media_list_player_new()
236 o=i.media_list_player_new()
239 def get_instance(self):
240 """Return the associated vlc.Instance.
242 return self._instance
249 if not self.has_next():
253 ret=libvlc_log_iterator_next(self, buf, e)
258 return self.get_iterator()
261 return [ str(m) for m in self ]