Commit f6cfac86 authored by Olivier Aubert's avatar Olivier Aubert

python-ctypes: try to detect plugin path on win32 / macosx

parent bbea92e7
...@@ -39,42 +39,52 @@ import sys ...@@ -39,42 +39,52 @@ import sys
build_date="This will be replaced by the build date" build_date="This will be replaced by the build date"
# Used for win32 and MacOS X
detected_plugin_path=None
if sys.platform == 'linux2': if sys.platform == 'linux2':
dll=ctypes.CDLL('libvlc.so') dll=ctypes.CDLL('libvlc.so')
elif sys.platform == 'win32': elif sys.platform == 'win32':
import ctypes.util import ctypes.util
import os import os
plugin_path=None detected_plugin_path=None
path=ctypes.util.find_library('libvlc.dll') path=ctypes.util.find_library('libvlc.dll')
if path is None: if path is None:
# Try to use registry settings # Try to use registry settings
import _winreg import _winreg
plugin_path_found = None detected_plugin_path_found = None
subkey, name = 'Software\\VideoLAN\\VLC','InstallDir' subkey, name = 'Software\\VideoLAN\\VLC','InstallDir'
for hkey in _winreg.HKEY_LOCAL_MACHINE, _winreg.HKEY_CURRENT_USER: for hkey in _winreg.HKEY_LOCAL_MACHINE, _winreg.HKEY_CURRENT_USER:
try: try:
reg = _winreg.OpenKey(hkey, subkey) reg = _winreg.OpenKey(hkey, subkey)
plugin_path_found, type_id = _winreg.QueryValueEx(reg, name) detected_plugin_path_found, type_id = _winreg.QueryValueEx(reg, name)
_winreg.CloseKey(reg) _winreg.CloseKey(reg)
break break
except _winreg.error: except _winreg.error:
pass pass
if plugin_path_found: if detected_plugin_path_found:
plugin_path = plugin_path_found detected_plugin_path = detected_plugin_path_found
else: else:
# Try a standard location. # Try a standard location.
p='c:\\Program Files\\VideoLAN\\VLC\\libvlc.dll' p='c:\\Program Files\\VideoLAN\\VLC\\libvlc.dll'
if os.path.exists(p): if os.path.exists(p):
plugin_path=os.path.dirname(p) detected_plugin_path=os.path.dirname(p)
os.chdir(plugin_path) os.chdir(detected_plugin_path)
# If chdir failed, this will not work and raise an exception # If chdir failed, this will not work and raise an exception
path='libvlc.dll' path='libvlc.dll'
else: else:
plugin_path=os.path.dirname(path) detected_plugin_path=os.path.dirname(path)
dll=ctypes.CDLL(path) dll=ctypes.CDLL(path)
elif sys.platform == 'darwin': elif sys.platform == 'darwin':
# FIXME: should find a means to configure path # FIXME: should find a means to configure path
dll=ctypes.CDLL('/Applications/VLC.app/Contents/MacOS/lib/libvlc.2.dylib') d='/Applications/VLC.app'
import os
if os.path.exists(d):
dll=ctypes.CDLL(d+'/Contents/MacOS/lib/libvlc.2.dylib')
detected_plugin_path=d+'/Contents/MacOS/modules'
else:
# Hope some default path is set...
dll=ctypes.CDLL('libvlc.2.dylib')
# #
# Generated enum types. # Generated enum types.
......
...@@ -24,6 +24,10 @@ class Instance: ...@@ -24,6 +24,10 @@ class Instance:
if p and isinstance(p[0], MediaControl): if p and isinstance(p[0], MediaControl):
return p[0].get_instance() return p[0].get_instance()
else: else:
if not p and detected_plugin_path is not None:
# No parameters passed. Under win32 and MacOS, specify
# the detected_plugin_path if present.
p=[ 'vlc', '--plugin-path='+ detected_plugin_path ]
e=VLCException() e=VLCException()
return libvlc_new(len(p), p, e) return libvlc_new(len(p), p, e)
...@@ -74,6 +78,10 @@ class MediaControl: ...@@ -74,6 +78,10 @@ class MediaControl:
e=MediaControlException() e=MediaControlException()
return mediacontrol_new_from_instance(p[0], e) return mediacontrol_new_from_instance(p[0], e)
else: else:
if not p and detected_plugin_path is not None:
# No parameters passed. Under win32 and MacOS, specify
# the detected_plugin_path if present.
p=[ 'vlc', '--plugin-path='+ detected_plugin_path ]
e=MediaControlException() e=MediaControlException()
return mediacontrol_new(len(p), p, e) return mediacontrol_new(len(p), p, e)
......
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