]> git.sesse.net Git - vlc/blob - bindings/python-ctypes/override.py
92da39ba9695e40218b2baedc360f28d6eefee19
[vlc] / bindings / python-ctypes / override.py
1 class Instance:
2     """Create a new Instance instance.
3
4     It may take as parameter either:
5      * a string
6      * a list of strings as first parameters
7      * the parameters given as the constructor parameters (must be strings)
8      * a MediaControl instance
9     """
10     def __new__(cls, *p):
11         if p and p[0] == 0:
12             return None
13         elif p and isinstance(p[0], (int, long)):
14             # instance creation from ctypes
15             o=object.__new__(cls)
16             o._as_parameter_=ctypes.c_void_p(p[0])
17             return o
18         elif len(p) == 1 and isinstance(p[0], basestring):
19             # Only 1 string parameter: should be a parameter line
20             p=p[0].split(' ')
21         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
22             p=p[0]
23
24         if p and isinstance(p[0], MediaControl):
25             return p[0].get_instance()
26         else:
27             e=VLCException()
28             return libvlc_new(len(p), p, e)
29
30     def media_player_new(self, uri=None):
31         """Create a new Media Player object.
32
33         @param uri: an optional URI to play in the player.
34         """
35         e=VLCException()
36         p=libvlc_media_player_new(self, e)
37         if uri:
38             p.set_media(self.media_new(uri))
39         p._instance=self
40         return p
41
42     def media_list_player_new(self):
43         """Create an empty Media Player object
44         """
45         e=VLCException()
46         p=libvlc_media_list_player_new(self, e)
47         p._instance=self
48         return p
49
50 class MediaControl:
51     """Create a new MediaControl instance
52
53     It may take as parameter either:
54      * a string
55      * a list of strings as first parameters
56      * the parameters given as the constructor parameters (must be strings)
57      * a vlc.Instance
58     """
59     def __new__(cls, *p):
60         if p and p[0] == 0:
61             return None
62         elif p and isinstance(p[0], (int, long)):
63             # instance creation from ctypes
64             o=object.__new__(cls)
65             o._as_parameter_=ctypes.c_void_p(p[0])
66             return o
67         elif len(p) == 1 and isinstance(p[0], basestring):
68             # Only 1 string parameter: should be a parameter line
69             p=p[0].split(' ')
70         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
71             p=p[0]
72
73         if p and isinstance(p[0], Instance):
74             e=MediaControlException()
75             return mediacontrol_new_from_instance(p[0])
76         else:
77             e=MediaControlException()
78             return mediacontrol_new(len(p), p, e)
79
80 class MediaPlayer:
81     """Create a new MediaPlayer instance.
82
83     It may take as parameter either:
84      * a string (media URI). In this case, a vlc.Instance will be created.
85      * a vlc.Instance
86     """
87     def __new__(cls, *p):
88         if p and p[0] == 0:
89             return None
90         elif p and isinstance(p[0], (int, long)):
91             # instance creation from ctypes
92             o=object.__new__(cls)
93             o._as_parameter_=ctypes.c_void_p(p[0])
94             return o
95
96         if p and isinstance(p[0], Instance):
97             return p[0].media_player_new()
98         else:
99             i=Instance()
100             o=i.media_player_new()
101             if p:
102                 o.set_media(i.media_new(p[0]))
103             return o
104
105     def get_instance(self):
106         return self._instance
107
108 class MediaListPlayer:
109     """Create a new MediaPlayer instance.
110
111     It may take as parameter either:
112      * a vlc.Instance
113      * nothing
114     """
115     def __new__(cls, *p):
116         if p and p[0] == 0:
117             return None
118         elif p and isinstance(p[0], (int, long)):
119             # instance creation from ctypes
120             o=object.__new__(cls)
121             o._as_parameter_=ctypes.c_void_p(p[0])
122             return o
123         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
124             p=p[0]
125
126         if p and isinstance(p[0], Instance):
127             return p[0].media_list_player_new()
128         else:
129             i=Instance()
130             o=i.media_list_player_new()
131             return o
132
133     def get_instance(self):
134         return self._instance
135
136 class LogIterator:
137     def __iter__(self):
138         return self