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)
55 """Create a new MediaControl instance
57 It may take as parameter either:
59 - a list of strings as first parameters
60 - the parameters given as the constructor parameters (must be strings)
66 elif p and isinstance(p[0], (int, long)):
67 # instance creation from ctypes
69 o._as_parameter_=ctypes.c_void_p(p[0])
71 elif len(p) == 1 and isinstance(p[0], basestring):
72 # Only 1 string parameter: should be a parameter line
74 elif len(p) == 1 and isinstance(p[0], (tuple, list)):
77 if p and isinstance(p[0], Instance):
78 e=MediaControlException()
79 return mediacontrol_new_from_instance(p[0], e)
81 if not p and detected_plugin_path is not None:
82 # No parameters passed. Under win32 and MacOS, specify
83 # the detected_plugin_path if present.
84 p=[ 'vlc', '--plugin-path='+ detected_plugin_path ]
85 e=MediaControlException()
86 return mediacontrol_new(len(p), p, e)
88 def get_media_position(self, origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime):
89 e=MediaControlException()
90 p=mediacontrol_get_media_position(self, origin, key, e)
96 def set_media_position(self, pos):
97 """Set the media position.
99 @param pos: a MediaControlPosition or an integer (in ms)
101 if not isinstance(pos, MediaControlPosition):
102 pos=MediaControlPosition(long(pos))
103 e=MediaControlException()
104 mediacontrol_set_media_position(self, pos, e)
106 def start(self, pos=0):
107 """Start the player at the given position.
109 @param pos: a MediaControlPosition or an integer (in ms)
111 if not isinstance(pos, MediaControlPosition):
112 pos=MediaControlPosition(long(pos))
113 e=MediaControlException()
114 mediacontrol_start(self, pos, e)
116 def snapshot(self, pos=0):
119 Note: the position parameter is not properly implemented. For
120 the moment, the only valid position is the 0-relative position
121 (i.e. the current position).
123 @param pos: a MediaControlPosition or an integer (in ms)
125 if not isinstance(pos, MediaControlPosition):
126 pos=MediaControlPosition(long(pos))
127 e=MediaControlException()
128 p=mediacontrol_snapshot(self, pos, e)
131 # FIXME: there is a bug in the current mediacontrol_snapshot
132 # implementation, which sets an incorrect date.
134 snap.date=self.get_media_position().value
139 def display_text(self, message='', begin=0, end=1000):
140 """Display a caption between begin and end positions.
142 @param message: the caption to display
143 @param begin: the begin position
144 @param end: the end position
146 if not isinstance(begin, MediaControlPosition):
147 begin=self.value2position(begin)
148 if not isinstance(end, MediaControlPosition):
149 end=self.value2position(end)
150 e=MediaControlException()
151 mediacontrol_display_text(self, message, begin, end, e)
153 def get_stream_information(self, key=PositionKey.MediaTime):
154 """Return information about the stream.
156 e=MediaControlException()
157 return mediacontrol_get_stream_information(self, key, e).contents
160 """Create a new MediaPlayer instance.
162 It may take as parameter either:
163 - a string (media URI). In this case, a vlc.Instance will be created.
166 def __new__(cls, *p):
169 elif p and isinstance(p[0], (int, long)):
170 # instance creation from ctypes
171 o=object.__new__(cls)
172 o._as_parameter_=ctypes.c_void_p(p[0])
175 if p and isinstance(p[0], Instance):
176 return p[0].media_player_new()
179 o=i.media_player_new()
181 o.set_media(i.media_new(p[0]))
184 def get_instance(self):
185 """Return the associated vlc.Instance.
187 return self._instance
189 class MediaListPlayer:
190 """Create a new MediaPlayer instance.
192 It may take as parameter either:
196 def __new__(cls, *p):
199 elif p and isinstance(p[0], (int, long)):
200 # instance creation from ctypes
201 o=object.__new__(cls)
202 o._as_parameter_=ctypes.c_void_p(p[0])
204 elif len(p) == 1 and isinstance(p[0], (tuple, list)):
207 if p and isinstance(p[0], Instance):
208 return p[0].media_list_player_new()
211 o=i.media_list_player_new()
214 def get_instance(self):
215 """Return the associated vlc.Instance.
217 return self._instance
224 if not self.has_next():
228 ret=libvlc_log_iterator_next(self, buf, e)
233 return self.get_iterator()
236 return [ str(m) for m in self ]