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()
28 return libvlc_new(len(p), p, e)
30 def media_player_new(self, uri=None):
31 """Create a new Media Player object.
33 @param uri: an optional URI to play in the player.
36 p=libvlc_media_player_new(self, e)
38 p.set_media(self.media_new(uri))
42 def media_list_player_new(self):
43 """Create an empty Media Player object
46 p=libvlc_media_list_player_new(self, e)
51 """Create a new MediaControl instance
53 It may take as parameter either:
55 - a list of strings as first parameters
56 - the parameters given as the constructor parameters (must be strings)
62 elif p and isinstance(p[0], (int, long)):
63 # instance creation from ctypes
65 o._as_parameter_=ctypes.c_void_p(p[0])
67 elif len(p) == 1 and isinstance(p[0], basestring):
68 # Only 1 string parameter: should be a parameter line
70 elif len(p) == 1 and isinstance(p[0], (tuple, list)):
73 if p and isinstance(p[0], Instance):
74 e=MediaControlException()
75 return mediacontrol_new_from_instance(p[0], e)
77 e=MediaControlException()
78 return mediacontrol_new(len(p), p, e)
80 def get_media_position(self, origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime):
81 e=MediaControlException()
82 p=mediacontrol_get_media_position(self, origin, key, e)
88 def set_media_position(self, pos):
89 """Set the media position.
91 @param pos: a MediaControlPosition or an integer (in ms)
93 if not isinstance(pos, MediaControlPosition):
94 pos=MediaControlPosition(long(pos))
95 e=MediaControlException()
96 mediacontrol_set_media_position(self, pos, e)
98 def start(self, pos=0):
99 """Start the player at the given position.
101 @param pos: a MediaControlPosition or an integer (in ms)
103 if not isinstance(pos, MediaControlPosition):
104 pos=MediaControlPosition(long(pos))
105 e=MediaControlException()
106 mediacontrol_start(self, pos, e)
108 def snapshot(self, pos=0):
111 Note: the position parameter is not properly implemented. For
112 the moment, the only valid position is the 0-relative position
113 (i.e. the current position).
115 @param pos: a MediaControlPosition or an integer (in ms)
117 if not isinstance(pos, MediaControlPosition):
118 pos=MediaControlPosition(long(pos))
119 e=MediaControlException()
120 p=mediacontrol_snapshot(self, pos, e)
123 # FIXME: there is a bug in the current mediacontrol_snapshot
124 # implementation, which sets an incorrect date.
126 snap.date=self.get_media_position().value
131 def display_text(self, message='', begin=0, end=1000):
132 """Display a caption between begin and end positions.
134 @param message: the caption to display
135 @param begin: the begin position
136 @param end: the end position
138 if not isinstance(begin, MediaControlPosition):
139 begin=self.value2position(pos)
140 if not isinstance(end, MediaControlPosition):
141 end=self.value2position(end)
142 e=MediaControlException()
143 mediacontrol_display_text(self, message, begin, end, e)
145 def get_stream_information(self, key=PositionKey.MediaTime):
146 """Return information about the stream.
148 e=MediaControlException()
149 return mediacontrol_get_stream_information(self, key, e).contents
152 """Create a new MediaPlayer instance.
154 It may take as parameter either:
155 - a string (media URI). In this case, a vlc.Instance will be created.
158 def __new__(cls, *p):
161 elif p and isinstance(p[0], (int, long)):
162 # instance creation from ctypes
163 o=object.__new__(cls)
164 o._as_parameter_=ctypes.c_void_p(p[0])
167 if p and isinstance(p[0], Instance):
168 return p[0].media_player_new()
171 o=i.media_player_new()
173 o.set_media(i.media_new(p[0]))
176 def get_instance(self):
177 """Return the associated vlc.Instance.
179 return self._instance
181 class MediaListPlayer:
182 """Create a new MediaPlayer instance.
184 It may take as parameter either:
188 def __new__(cls, *p):
191 elif p and isinstance(p[0], (int, long)):
192 # instance creation from ctypes
193 o=object.__new__(cls)
194 o._as_parameter_=ctypes.c_void_p(p[0])
196 elif len(p) == 1 and isinstance(p[0], (tuple, list)):
199 if p and isinstance(p[0], Instance):
200 return p[0].media_list_player_new()
203 o=i.media_list_player_new()
206 def get_instance(self):
207 """Return the associated vlc.Instance.
209 return self._instance
216 if not self.has_next():
220 ret=libvlc_log_iterator_next(self, buf, e)
225 return self.get_iterator()
228 return [ str(m) for m in self ]