L{MediaPlayer} and L{MediaListPlayer} instances.
"""
+import logging
import ctypes
import sys
plugin_path=None
path=ctypes.util.find_library('libvlc.dll')
if path is None:
- # Try a standard location.
- p='c:\\Program Files\\VideoLAN\\VLC\\libvlc.dll'
- if os.path.exists(p):
- plugin_path=os.path.dirname(p)
- os.chdir(plugin_path)
+ # Try to use registry settings
+ import _winreg
+ plugin_path_found = None
+ subkey, name = 'Software\\VideoLAN\\VLC','InstallDir'
+ for hkey in _winreg.HKEY_LOCAL_MACHINE, _winreg.HKEY_CURRENT_USER:
+ try:
+ reg = _winreg.OpenKey(hkey, subkey)
+ plugin_path_found, type_id = _winreg.QueryValueEx(reg, name)
+ _winreg.CloseKey(reg)
+ break
+ except _winreg.error:
+ pass
+ if plugin_path_found:
+ plugin_path = plugin_path_found
+ else:
+ # Try a standard location.
+ p='c:\\Program Files\\VideoLAN\\VLC\\libvlc.dll'
+ if os.path.exists(p):
+ plugin_path=os.path.dirname(p)
+ os.chdir(plugin_path)
# If chdir failed, this will not work and raise an exception
path='libvlc.dll'
else:
pass
# From libvlc_structures.h
-class VLCException(ctypes.Structure):
- """libvlc exception.
- """
- _fields_= [
- ('raised', ctypes.c_int),
- ('code', ctypes.c_int),
- ('message', ctypes.c_char_p),
- ]
- def init(self):
- libvlc_exception_init(self)
- def clear(self):
- libvlc_exception_clear(self)
+# This is version-dependent, depending on the presence of libvlc_exception_get_message.
+
+if hasattr(dll, 'libvlc_exception_get_message'):
+ # New-style message passing
+ class VLCException(ctypes.Structure):
+ """libvlc exception.
+ """
+ _fields_= [
+ ('raised', ctypes.c_int),
+ ]
+
+ @property
+ def message(self):
+ return dll.libvlc_exception_get_message()
+
+ def init(self):
+ libvlc_exception_init(self)
+
+ def clear(self):
+ libvlc_exception_clear(self)
+else:
+ # Old-style exceptions
+ class VLCException(ctypes.Structure):
+ """libvlc exception.
+ """
+ _fields_= [
+ ('raised', ctypes.c_int),
+ ('code', ctypes.c_int),
+ ('message', ctypes.c_char_p),
+ ]
+ def init(self):
+ libvlc_exception_init(self)
+
+ def clear(self):
+ libvlc_exception_clear(self)
class PlaylistItem(ctypes.Structure):
_fields_= [
"""Error checking method for functions using an exception in/out parameter.
"""
ex=args[-1]
+ if not isinstance(ex, (VLCException, MediaControlException)):
+ logging.warn("python-vlc: error when processing function %s. Please report this as a bug to vlc-devel@videolan.org" % str(func))
+ return result
# Take into account both VLCException and MediacontrolException:
c=getattr(ex, 'raised', getattr(ex, 'code', 0))
if c:
- raise LibVLCException(args[-1].message)
+ raise LibVLCException(ex.message)
return result
### End of header.py ###