← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol/openlp/bug-966086 into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol/openlp/bug-966086 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #966086 in OpenLP: "Enabling VLC causes stack trace and prevents OpenLP from starting"
  https://bugs.launchpad.net/openlp/+bug/966086

For more details, see:
https://code.launchpad.net/~googol/openlp/bug-966086/+merge/103979

Hello,

- various clean ups
- fixed bug #966086
-- 
https://code.launchpad.net/~googol/openlp/bug-966086/+merge/103979
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/bug-966086 into lp:openlp.
=== modified file 'openlp/core/ui/media/__init__.py'
--- openlp/core/ui/media/__init__.py	2012-03-21 19:30:18 +0000
+++ openlp/core/ui/media/__init__.py	2012-04-28 13:21:21 +0000
@@ -69,12 +69,13 @@
 def get_media_players():
     """
     This method extract the configured media players and overridden player from
-    the settings
+    the settings.
 
     ``players_list``
-        this is a python list with all active media players
+       A list with all active media players.
+
     ``overridden_player``
-        here an special media player is choosen for all media actions
+        Here an special media player is chosen for all media actions.
     """
     log.debug(u'get_media_players')
     players = unicode(QtCore.QSettings().value(u'media/players').toString())
@@ -92,15 +93,17 @@
     players_list = players.replace(u'[', u'').replace(u']', u'').split(u',')
     return players_list, overridden_player
 
+
 def set_media_players(players_list, overridden_player=u'auto'):
     """
     This method saves the configured media players and overridden player to the
     settings
 
     ``players_list``
-        this is a python list with all active media players
+        A list with all active media players.
+
     ``overridden_player``
-        here an special media player is choosen for all media actions
+        Here an special media player is chosen for all media actions.
     """
     log.debug(u'set_media_players')
     players = u','.join(players_list)

=== modified file 'openlp/core/ui/media/mediacontroller.py'
--- openlp/core/ui/media/mediacontroller.py	2012-03-21 19:30:18 +0000
+++ openlp/core/ui/media/mediacontroller.py	2012-04-28 13:21:21 +0000
@@ -84,10 +84,7 @@
     def set_active_players(self):
         savedPlayers = get_media_players()[0]
         for player in self.mediaPlayers.keys():
-            if player in savedPlayers:
-                self.mediaPlayers[player].isActive = True
-            else:
-                self.mediaPlayers[player].isActive = False
+            self.mediaPlayers[player].isActive = player in savedPlayers
 
     def register_controllers(self, controller):
         """
@@ -106,8 +103,8 @@
             AppLocation.get_directory(AppLocation.AppDir),
             u'core', u'ui', u'media')
         for filename in os.listdir(controller_dir):
-            if filename.endswith(u'player.py') and \
-                not filename == 'media_player.py':
+            if filename.endswith(u'player.py') and not \
+                filename == 'media_player.py':
                 path = os.path.join(controller_dir, filename)
                 if os.path.isfile(path):
                     modulename = u'openlp.core.ui.media.' + \
@@ -122,38 +119,36 @@
         for controller_class in controller_classes:
             controller = controller_class(self)
             self.register_controllers(controller)
-        if self.mediaPlayers:
-            savedPlayers, overriddenPlayer = get_media_players()
-            invalidMediaPlayers = [mediaPlayer for mediaPlayer in savedPlayers \
-                if not mediaPlayer in self.mediaPlayers or \
-                not self.mediaPlayers[mediaPlayer].check_available()]
-            if len(invalidMediaPlayers) > 0:
-                for invalidPlayer in invalidMediaPlayers:
-                    savedPlayers.remove(invalidPlayer)
-                set_media_players(savedPlayers, overriddenPlayer)
-            self.set_active_players()
-            return True
-        else:
+        if not self.mediaPlayers:
             return False
+        savedPlayers, overriddenPlayer = get_media_players()
+        invalidMediaPlayers = [mediaPlayer for mediaPlayer in savedPlayers
+            if not mediaPlayer in self.mediaPlayers or not
+            self.mediaPlayers[mediaPlayer].check_available()]
+        if invalidMediaPlayers:
+            for invalidPlayer in invalidMediaPlayers:
+                savedPlayers.remove(invalidPlayer)
+            set_media_players(savedPlayers, overriddenPlayer)
+        self.set_active_players()
+        return True
 
     def video_state(self):
         """
         Check if there is a running media Player and do updating stuff (e.g.
         update the UI)
         """
-        if len(self.curDisplayMediaPlayer.keys()) == 0:
+        if not self.curDisplayMediaPlayer.keys():
             self.timer.stop()
         else:
             for display in self.curDisplayMediaPlayer.keys():
                 self.curDisplayMediaPlayer[display].resize(display)
                 self.curDisplayMediaPlayer[display].update_ui(display)
-                if self.curDisplayMediaPlayer[display] \
-                    .state == MediaState.Playing:
+                if self.curDisplayMediaPlayer[display].state == \
+                    MediaState.Playing:
                     return
         # no players are active anymore
         for display in self.curDisplayMediaPlayer.keys():
-            if self.curDisplayMediaPlayer[display] \
-                .state != MediaState.Paused:
+            if self.curDisplayMediaPlayer[display].state != MediaState.Paused:
                 display.controller.seekSlider.setSliderPosition(0)
         self.timer.stop()
 
@@ -333,8 +328,7 @@
                 'Unsupported File')))
             return False
         # dont care about actual theme, set a black background
-        if controller.isLive and ( \
-            controller.media_info.is_background == False):
+        if controller.isLive and not controller.media_info.is_background:
             display.frame.evaluateJavaScript(u'show_video( \
             "setBackBoard", null, null, null,"visible");')
         # now start playing
@@ -395,7 +389,7 @@
         """
         Responds to the request to play a loaded video
 
-         ``msg``
+        ``msg``
             First element is the controller which should be used
         """
         log.debug(u'video_play')
@@ -497,15 +491,15 @@
             First element is the boolean for Live indication
         """
         isLive = msg[1]
-        if isLive:
-            controller = self.parent.liveController
-            for display in self.curDisplayMediaPlayer.keys():
-                if display.controller == controller:
-                    if self.curDisplayMediaPlayer[display] \
-                        .state == MediaState.Playing:
-                        self.curDisplayMediaPlayer[display].pause(display)
-                        self.curDisplayMediaPlayer[display] \
-                            .set_visible(display, False)
+        if not isLive:
+            return
+        controller = self.parent.liveController
+        for display in self.curDisplayMediaPlayer.keys():
+            if display.controller != controller or  \
+                self.curDisplayMediaPlayer[display].state != MediaState.Playing:
+                continue
+            self.curDisplayMediaPlayer[display].pause(display)
+            self.curDisplayMediaPlayer[display].set_visible(display, False)
 
     def video_blank(self, msg):
         """
@@ -517,16 +511,16 @@
         """
         isLive = msg[1]
         hide_mode = msg[2]
-        if isLive:
-            Receiver.send_message(u'live_display_hide', hide_mode)
-            controller = self.parent.liveController
-            for display in self.curDisplayMediaPlayer.keys():
-                if display.controller == controller:
-                    if self.curDisplayMediaPlayer[display] \
-                        .state == MediaState.Playing:
-                        self.curDisplayMediaPlayer[display].pause(display)
-                        self.curDisplayMediaPlayer[display] \
-                            .set_visible(display, False)
+        if not isLive:
+            return
+        Receiver.send_message(u'live_display_hide', hide_mode)
+        controller = self.parent.liveController
+        for display in self.curDisplayMediaPlayer.keys():
+            if display.controller != controller or \
+                self.curDisplayMediaPlayer[display].state != MediaState.Playing:
+                continue
+            self.curDisplayMediaPlayer[display].pause(display)
+            self.curDisplayMediaPlayer[display].set_visible(display, False)
 
     def video_unblank(self, msg):
         """
@@ -538,19 +532,18 @@
         """
         Receiver.send_message(u'live_display_show')
         isLive = msg[1]
-        if isLive:
-            controller = self.parent.liveController
-            for display in self.curDisplayMediaPlayer.keys():
-                if display.controller == controller:
-                    if self.curDisplayMediaPlayer[display] \
-                        .state == MediaState.Paused:
-                        if self.curDisplayMediaPlayer[display].play(display):
-                            self.curDisplayMediaPlayer[display] \
-                                .set_visible(display, True)
-                                    # Start Timer for ui updates
-                            if not self.timer.isActive():
-                                self.timer.start()
-
+        if not isLive:
+            return
+        controller = self.parent.liveController
+        for display in self.curDisplayMediaPlayer.keys():
+            if display.controller != controller or \
+                self.curDisplayMediaPlayer[display].state != MediaState.Paused:
+                continue
+            if self.curDisplayMediaPlayer[display].play(display):
+                self.curDisplayMediaPlayer[display].set_visible(display, True)
+                # Start Timer for ui updates
+                if not self.timer.isActive():
+                    self.timer.start()
 
     def get_audio_extensions_list(self):
         audio_list = []
@@ -565,9 +558,8 @@
         video_list = []
         for player in self.mediaPlayers.values():
             if player.isActive:
-                for item in player.video_extensions_list:
-                    if not item in video_list:
-                        video_list.append(item)
+                video_list.extend([item for item in player.video_extensions_list
+                    if item not in video_list])
         return video_list
 
     def finalise(self):

=== modified file 'openlp/core/ui/media/vlcplayer.py'
--- openlp/core/ui/media/vlcplayer.py	2012-03-13 19:54:16 +0000
+++ openlp/core/ui/media/vlcplayer.py	2012-04-28 13:21:21 +0000
@@ -25,29 +25,41 @@
 # Temple Place, Suite 330, Boston, MA 02111-1307 USA                          #
 ###############################################################################
 
+from datetime import datetime
+from distutils.version import LooseVersion
 import logging
-import sys, os
-from datetime import datetime
+import os
+import sys
+
+from PyQt4 import QtCore, QtGui
+
+from openlp.core.lib import Receiver
+from openlp.core.lib.mediaplayer import MediaPlayer
+from openlp.core.ui.media import MediaState
+
+log = logging.getLogger(__name__)
+
+VLC_AVAILABLE = False
 try:
     import vlc
-    vlc_available = bool(vlc.get_default_instance())
+    VLC_AVAILABLE = bool(vlc.get_default_instance())
 except (ImportError, NameError):
-    vlc_available = False
+    pass
 except OSError, e:
     if sys.platform.startswith('win'):
-        if isinstance(e, WindowsError) and e.winerror == 126:
-            vlc_available = False
-        else:
+        if not isinstance(e, WindowsError) and e.winerror != 126:
             raise
     else:
         raise
 
-from PyQt4 import QtCore, QtGui
-from openlp.core.lib import Receiver
-from openlp.core.lib.mediaplayer import MediaPlayer
-from openlp.core.ui.media import MediaState
-
-log = logging.getLogger(__name__)
+if VLC_AVAILABLE:
+    try:
+        version = vlc.libvlc_get_version()
+    except:
+        version = u'0.0.0'
+    if LooseVersion(version) < '1.1.0':
+        VLC_AVAILABLE = False
+        log.debug(u'VLC could not be loaded: %s' % version)
 
 AUDIO_EXT = [
       u'*.mp3'
@@ -128,7 +140,7 @@
         self.hasOwnWidget = True
 
     def check_available(self):
-        return vlc_available
+        return VLC_AVAILABLE
 
     def load(self, display):
         log.debug(u'load vid in Vlc Controller')


Follow ups