[Media Players] Added better detection for VLC, with thanks to Tomas.

This commit is contained in:
Raoul Snyman 2015-10-28 01:30:49 +02:00
parent 50ceb568e5
commit 851af0b7a5
2 changed files with 22 additions and 5 deletions

View File

@ -84,7 +84,9 @@ def get_vlc():
pass pass
if is_vlc_available: if is_vlc_available:
try: try:
vlc_instance = vlc.Instance()
VERSION = vlc.libvlc_get_version().decode('UTF-8') VERSION = vlc.libvlc_get_version().decode('UTF-8')
vlc_instance.release()
except: except:
VERSION = '0.0.0' VERSION = '0.0.0'
# LooseVersion does not work when a string contains letter and digits (e. g. 2.0.5 Twoflower). # LooseVersion does not work when a string contains letter and digits (e. g. 2.0.5 Twoflower).
@ -95,6 +97,9 @@ def get_vlc():
if is_vlc_available: if is_vlc_available:
return vlc return vlc
else: else:
# The vlc module may have been imported. Remove it if it has.
if 'openlp.core.ui.media.vendor.vlc' in sys.modules:
del sys.modules['openlp.core.ui.media.vendor.vlc']
return None return None

View File

@ -25,7 +25,7 @@ Package to test the openlp.core.ui.media.vlcplayer package.
import os import os
import sys import sys
from datetime import datetime, timedelta from datetime import datetime, timedelta
from unittest import TestCase from unittest import TestCase, skip
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.core.ui.media import MediaState, MediaType from openlp.core.ui.media import MediaState, MediaType
@ -50,6 +50,22 @@ class TestVLCPlayer(TestCase, TestMixin):
del sys.modules['openlp.core.ui.media.vendor.vlc'] del sys.modules['openlp.core.ui.media.vendor.vlc']
MockDateTime.revert() MockDateTime.revert()
@skip('No way to test this')
@patch('openlp.core.ui.media.vlcplayer.vlc')
def get_vlc_fails_and_removes_module_test(self, mocked_vlc):
"""
Test that when the VLC import fails, it removes the module from sys.modules
"""
# GIVEN: We're on OS X and we don't have the VLC plugin path set
mocked_vlc.Instance.side_effect = NameError
mocked_vlc.libvlc_get_version.return_value = b'0.0.0'
# WHEN: An checking if the player is available
get_vlc()
# THEN: The extra environment variable should be there
self.assertNotIn('openlp.core.ui.media.vendor.vlc', sys.modules)
@patch('openlp.core.ui.media.vlcplayer.is_macosx') @patch('openlp.core.ui.media.vlcplayer.is_macosx')
def fix_vlc_22_plugin_path_test(self, mocked_is_macosx): def fix_vlc_22_plugin_path_test(self, mocked_is_macosx):
""" """
@ -74,10 +90,6 @@ class TestVLCPlayer(TestCase, TestMixin):
""" """
# GIVEN: We're not on OS X and we don't have the VLC plugin path set # GIVEN: We're not on OS X and we don't have the VLC plugin path set
mocked_is_macosx.return_value = False mocked_is_macosx.return_value = False
if 'VLC_PLUGIN_PATH' in os.environ:
del os.environ['VLC_PLUGIN_PATH']
if 'openlp.core.ui.media.vendor.vlc' in sys.modules:
del sys.modules['openlp.core.ui.media.vendor.vlc']
# WHEN: An checking if the player is available # WHEN: An checking if the player is available
get_vlc() get_vlc()