From 2e1208e690a1381c11c8bb3e40fa1273dfb0f83f Mon Sep 17 00:00:00 2001 From: Olivier Aubert Date: Fri, 31 Jul 2009 17:06:25 +0200 Subject: [PATCH] python-ctypes: offer shortcuts for MediaList and MediaListPlayer creation --- bindings/python-ctypes/override.py | 84 +++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/bindings/python-ctypes/override.py b/bindings/python-ctypes/override.py index e9542d2ac8..92da39ba96 100644 --- a/bindings/python-ctypes/override.py +++ b/bindings/python-ctypes/override.py @@ -17,7 +17,7 @@ class Instance: return o elif len(p) == 1 and isinstance(p[0], basestring): # Only 1 string parameter: should be a parameter line - p=p[0].split() + p=p[0].split(' ') elif len(p) == 1 and isinstance(p[0], (tuple, list)): p=p[0] @@ -27,6 +27,26 @@ class Instance: e=VLCException() return libvlc_new(len(p), p, e) + def media_player_new(self, uri=None): + """Create a new Media Player object. + + @param uri: an optional URI to play in the player. + """ + e=VLCException() + p=libvlc_media_player_new(self, e) + if uri: + p.set_media(self.media_new(uri)) + p._instance=self + return p + + def media_list_player_new(self): + """Create an empty Media Player object + """ + e=VLCException() + p=libvlc_media_list_player_new(self, e) + p._instance=self + return p + class MediaControl: """Create a new MediaControl instance @@ -46,7 +66,7 @@ class MediaControl: return o elif len(p) == 1 and isinstance(p[0], basestring): # Only 1 string parameter: should be a parameter line - p=p[0].split() + p=p[0].split(' ') elif len(p) == 1 and isinstance(p[0], (tuple, list)): p=p[0] @@ -56,3 +76,63 @@ class MediaControl: else: e=MediaControlException() return mediacontrol_new(len(p), p, e) + +class MediaPlayer: + """Create a new MediaPlayer instance. + + It may take as parameter either: + * a string (media URI). In this case, a vlc.Instance will be created. + * a vlc.Instance + """ + def __new__(cls, *p): + if p and p[0] == 0: + return None + elif p and isinstance(p[0], (int, long)): + # instance creation from ctypes + o=object.__new__(cls) + o._as_parameter_=ctypes.c_void_p(p[0]) + return o + + if p and isinstance(p[0], Instance): + return p[0].media_player_new() + else: + i=Instance() + o=i.media_player_new() + if p: + o.set_media(i.media_new(p[0])) + return o + + def get_instance(self): + return self._instance + +class MediaListPlayer: + """Create a new MediaPlayer instance. + + It may take as parameter either: + * a vlc.Instance + * nothing + """ + def __new__(cls, *p): + if p and p[0] == 0: + return None + elif p and isinstance(p[0], (int, long)): + # instance creation from ctypes + o=object.__new__(cls) + o._as_parameter_=ctypes.c_void_p(p[0]) + return o + elif len(p) == 1 and isinstance(p[0], (tuple, list)): + p=p[0] + + if p and isinstance(p[0], Instance): + return p[0].media_list_player_new() + else: + i=Instance() + o=i.media_list_player_new() + return o + + def get_instance(self): + return self._instance + +class LogIterator: + def __iter__(self): + return self -- 2.39.5