forked from openlp/openlp
"Only import vlc in one place. Make it work with PyInstaller.
Added bit-install-hint for VLC Pep8 fixes " bzr-revno: 2583
This commit is contained in:
commit
0d66ccdae4
@ -22,6 +22,7 @@
|
||||
"""
|
||||
The :mod:`~openlp.core.ui.media.playertab` module holds the configuration tab for the media stuff.
|
||||
"""
|
||||
import platform
|
||||
from PyQt5 import QtCore, QtWidgets
|
||||
|
||||
from openlp.core.common import Registry, Settings, UiStrings, translate
|
||||
@ -250,4 +251,9 @@ class PlayerTab(SettingsTab):
|
||||
if player.available:
|
||||
checkbox.setText(player.display_name)
|
||||
else:
|
||||
checkbox.setText(translate('OpenLP.PlayerTab', '%s (unavailable)') % player.display_name)
|
||||
checkbox_text = translate('OpenLP.PlayerTab', '%s (unavailable)') % player.display_name
|
||||
if player.name == 'vlc':
|
||||
checkbox_text += ' ' + translate('OpenLP.PlayerTab',
|
||||
'NOTE: To use VLC you must install the %s version',
|
||||
'Will insert "32bit" or "64bit"') % platform.architecture()[0]
|
||||
checkbox.setText(checkbox_text)
|
||||
|
@ -28,7 +28,7 @@ import logging
|
||||
import os
|
||||
import threading
|
||||
import sys
|
||||
|
||||
import ctypes
|
||||
from PyQt5 import QtWidgets
|
||||
|
||||
from openlp.core.common import Settings, is_win, is_macosx, is_linux
|
||||
@ -65,14 +65,24 @@ def get_vlc():
|
||||
if 'openlp.core.ui.media.vendor.vlc' in sys.modules:
|
||||
# If VLC has already been imported, no need to do all the stuff below again
|
||||
return sys.modules['openlp.core.ui.media.vendor.vlc']
|
||||
|
||||
is_vlc_available = False
|
||||
try:
|
||||
if is_macosx():
|
||||
# Newer versions of VLC on OS X need this. See https://forum.videolan.org/viewtopic.php?t=124521
|
||||
os.environ['VLC_PLUGIN_PATH'] = '/Applications/VLC.app/Contents/MacOS/plugins'
|
||||
# On Windows when frozen in PyInstaller, we need to blank SetDllDirectoryW to allow loading of the VLC dll.
|
||||
# This is due to limitations (by desgin) in PyInstaller. SetDllDirectoryW original value is restored once
|
||||
# VLC has been imported.
|
||||
if is_win():
|
||||
buffer_size = 1024
|
||||
dll_directory = ctypes.create_unicode_buffer(buffer_size)
|
||||
new_buffer_size = ctypes.windll.kernel32.GetDllDirectoryW(buffer_size, dll_directory)
|
||||
dll_directory = ''.join(dll_directory[:new_buffer_size]).replace('\0', '')
|
||||
log.debug('Original DllDirectory: %s' % dll_directory)
|
||||
ctypes.windll.kernel32.SetDllDirectoryW(None)
|
||||
from openlp.core.ui.media.vendor import vlc
|
||||
|
||||
if is_win():
|
||||
ctypes.windll.kernel32.SetDllDirectoryW(dll_directory)
|
||||
is_vlc_available = bool(vlc.get_default_instance())
|
||||
except (ImportError, NameError, NotImplementedError):
|
||||
pass
|
||||
|
@ -31,6 +31,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
from openlp.core.common import translate, is_win, is_linux, is_macosx, RegistryProperties
|
||||
from openlp.plugins.media.forms.mediaclipselectordialog import Ui_MediaClipSelector
|
||||
from openlp.core.lib.ui import critical_error_message_box
|
||||
from openlp.core.ui.media.vlcplayer import get_vlc
|
||||
|
||||
if is_win():
|
||||
from win32com.client import Dispatch
|
||||
@ -38,17 +39,6 @@ if is_win():
|
||||
if is_linux():
|
||||
import dbus
|
||||
|
||||
try:
|
||||
from openlp.core.ui.media.vendor import vlc
|
||||
except (ImportError, NameError, NotImplementedError):
|
||||
pass
|
||||
except OSError as e:
|
||||
if is_win():
|
||||
if not isinstance(e, WindowsError) and e.winerror != 126:
|
||||
raise
|
||||
else:
|
||||
raise
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -126,6 +116,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
|
||||
"""
|
||||
Setup VLC instance and mediaplayer
|
||||
"""
|
||||
vlc = get_vlc()
|
||||
self.vlc_instance = vlc.Instance()
|
||||
# creating an empty vlc media player
|
||||
self.vlc_media_player = self.vlc_instance.media_player_new()
|
||||
@ -160,6 +151,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
|
||||
:param path: Path to the device to be tested.
|
||||
:return: True if it was an audio CD else False.
|
||||
"""
|
||||
vlc = get_vlc()
|
||||
# Detect by trying to play it as a CD
|
||||
self.vlc_media = self.vlc_instance.media_new_location('cdda://' + path)
|
||||
self.vlc_media_player.set_media(self.vlc_media)
|
||||
@ -193,6 +185,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
|
||||
:param clicked: Given from signal, not used.
|
||||
"""
|
||||
log.debug('on_load_disc_button_clicked')
|
||||
vlc = get_vlc()
|
||||
self.disable_all()
|
||||
self.application.set_busy_cursor()
|
||||
path = self.media_path_combobox.currentText()
|
||||
@ -281,6 +274,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
|
||||
|
||||
:param clicked: Given from signal, not used.
|
||||
"""
|
||||
vlc = get_vlc()
|
||||
if self.vlc_media_player.get_state() == vlc.State.Playing:
|
||||
self.vlc_media_player.pause()
|
||||
self.play_button.setIcon(self.play_icon)
|
||||
@ -381,6 +375,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
|
||||
:param index: The index of the newly chosen title track.
|
||||
"""
|
||||
log.debug('in on_titles_combo_box_changed, index: %d', index)
|
||||
vlc = get_vlc()
|
||||
if not self.vlc_media_player:
|
||||
log.error('vlc_media_player was None')
|
||||
return
|
||||
@ -619,6 +614,7 @@ class MediaClipSelectorForm(QtWidgets.QDialog, Ui_MediaClipSelector, RegistryPro
|
||||
:param media_state: VLC media state to wait for.
|
||||
:return: True if state was reached within 15 seconds, False if not or error occurred.
|
||||
"""
|
||||
vlc = get_vlc()
|
||||
start = datetime.now()
|
||||
while media_state != self.vlc_media_player.get_state():
|
||||
if self.vlc_media_player.get_state() == vlc.State.Error:
|
||||
|
@ -220,4 +220,3 @@ class SongSelectImport(object):
|
||||
db_song.add_author(author)
|
||||
self.db_manager.save_object(db_song)
|
||||
return db_song
|
||||
|
||||
|
@ -427,4 +427,3 @@ if __name__ == '__main__':
|
||||
else:
|
||||
if not main():
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -51,7 +51,7 @@ class TestMediaClipSelectorForm(TestCase, TestMixin):
|
||||
self.main_window = QtWidgets.QMainWindow()
|
||||
Registry().register('main_window', self.main_window)
|
||||
# Mock VLC so we don't actually use it
|
||||
self.vlc_patcher = patch('openlp.plugins.media.forms.mediaclipselectorform.vlc')
|
||||
self.vlc_patcher = patch('openlp.plugins.media.forms.mediaclipselectorform.get_vlc')
|
||||
self.vlc_patcher.start()
|
||||
Registry().register('application', self.app)
|
||||
# Mock the media item
|
||||
|
Loading…
Reference in New Issue
Block a user