Commit 2e1208e6 authored by Olivier Aubert's avatar Olivier Aubert

python-ctypes: offer shortcuts for MediaList and MediaListPlayer creation

parent 8cc51ed5
...@@ -17,7 +17,7 @@ class Instance: ...@@ -17,7 +17,7 @@ class Instance:
return o return o
elif len(p) == 1 and isinstance(p[0], basestring): elif len(p) == 1 and isinstance(p[0], basestring):
# Only 1 string parameter: should be a parameter line # 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)): elif len(p) == 1 and isinstance(p[0], (tuple, list)):
p=p[0] p=p[0]
...@@ -27,6 +27,26 @@ class Instance: ...@@ -27,6 +27,26 @@ class Instance:
e=VLCException() e=VLCException()
return libvlc_new(len(p), p, e) 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: class MediaControl:
"""Create a new MediaControl instance """Create a new MediaControl instance
...@@ -46,7 +66,7 @@ class MediaControl: ...@@ -46,7 +66,7 @@ class MediaControl:
return o return o
elif len(p) == 1 and isinstance(p[0], basestring): elif len(p) == 1 and isinstance(p[0], basestring):
# Only 1 string parameter: should be a parameter line # 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)): elif len(p) == 1 and isinstance(p[0], (tuple, list)):
p=p[0] p=p[0]
...@@ -56,3 +76,63 @@ class MediaControl: ...@@ -56,3 +76,63 @@ class MediaControl:
else: else:
e=MediaControlException() e=MediaControlException()
return mediacontrol_new(len(p), p, e) 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment