← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~j-corwin/openlp/general into lp:openlp

 

Jonathan Corwin has proposed merging lp:~j-corwin/openlp/general into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #634771 in OpenLP: "OpenLP 1.9.2+bzr1016-0ubuntu1~lucid1 does not start"
  https://bugs.launchpad.net/openlp/+bug/634771
  Bug #646718 in OpenLP: "Songbook, Number will not loaded, Title will not be saved"
  https://bugs.launchpad.net/openlp/+bug/646718
  Bug #696013 in OpenLP: "song import from powerpoint crashes every second time"
  https://bugs.launchpad.net/openlp/+bug/696013
  Bug #696021 in OpenLP: "presentation loader does not work fine in Windows using Powerpoint Viewer 2007"
  https://bugs.launchpad.net/openlp/+bug/696021
  Bug #696637 in OpenLP: "Alert not positioned correctly in single screen"
  https://bugs.launchpad.net/openlp/+bug/696637
  Bug #727732 in OpenLP: "Openlp 1.9.?? crashes on start"
  https://bugs.launchpad.net/openlp/+bug/727732
  Bug #735039 in OpenLP: "Cannot import PowerPoint Presentations with PowerPoint 2010"
  https://bugs.launchpad.net/openlp/+bug/735039

For more details, see:
https://code.launchpad.net/~j-corwin/openlp/general/+merge/54116

Detect whether media files are supported before attempting to play them and bringing the machine to a grinding halt.

Note, due to string freeze, I've nicked an existing translate string from the presentation plugin. Will give it it's own string after beta.
-- 
https://code.launchpad.net/~j-corwin/openlp/general/+merge/54116
Your team OpenLP Core is requested to review the proposed merge of lp:~j-corwin/openlp/general into lp:openlp.
=== modified file 'openlp/core/ui/maindisplay.py'
--- openlp/core/ui/maindisplay.py	2011-03-15 20:03:25 +0000
+++ openlp/core/ui/maindisplay.py	2011-03-19 22:57:29 +0000
@@ -110,7 +110,7 @@
         Phonon.createPath(self.mediaObject, self.audio)
         QtCore.QObject.connect(self.mediaObject,
             QtCore.SIGNAL(u'stateChanged(Phonon::State, Phonon::State)'),
-            self.videoStart)
+            self.videoState)
         QtCore.QObject.connect(self.mediaObject,
             QtCore.SIGNAL(u'finished()'),
             self.videoFinished)
@@ -378,11 +378,13 @@
             Receiver.send_message(u'maindisplay_active')
         return self.preview()
 
-    def videoStart(self, newState, oldState):
+    def videoState(self, newState, oldState):
         """
         Start the video at a predetermined point.
         """
-        if newState == Phonon.PlayingState:
+        if newState == Phonon.PlayingState \
+            and oldState != Phonon.PausedState \
+            and self.serviceItem.start_time > 0:
             # set start time in milliseconds
             self.mediaObject.seek(self.serviceItem.start_time * 1000)
 

=== modified file 'openlp/plugins/media/lib/mediaitem.py'
--- openlp/plugins/media/lib/mediaitem.py	2011-03-18 19:15:07 +0000
+++ openlp/plugins/media/lib/mediaitem.py	2011-03-19 22:57:29 +0000
@@ -36,7 +36,7 @@
 from PyQt4.phonon import Phonon
 
 log = logging.getLogger(__name__)
-
+    
 class MediaMediaItem(MediaManagerItem):
     """
     This is the custom media manager item for Media Slides.
@@ -54,9 +54,6 @@
         QtCore.QObject.connect(Receiver.get_receiver(),
             QtCore.SIGNAL(u'video_background_replaced'),
             self.videobackgroundReplaced)
-        QtCore.QObject.connect(self.mediaObject,
-            QtCore.SIGNAL(u'stateChanged(Phonon::State, Phonon::State)'),
-            self.videoStart)
 
     def retranslateUi(self):
         self.onNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media')
@@ -125,41 +122,67 @@
             if item is None:
                 return False
         filename = unicode(item.data(QtCore.Qt.UserRole).toString())
-        if os.path.exists(filename):
-            self.mediaState = None
-            self.mediaObject.stop()
-            self.mediaObject.clearQueue()
-            self.mediaObject.setCurrentSource(Phonon.MediaSource(filename))
-            self.mediaObject.play()
-            service_item.title = unicode(self.plugin.nameStrings[u'singular'])
-            service_item.add_capability(ItemCapabilities.RequiresMedia)
-            # force a nonexistent theme
-            service_item.theme = -1
-            frame = u':/media/image_clapperboard.png'
-            (path, name) = os.path.split(filename)
-            file_size = os.path.getsize(filename)
-            # File too big for processing
-            if file_size <= 52428800: # 50MiB
-                start = datetime.now()
-                while not self.mediaState:
-                    Receiver.send_message(u'openlp_process_events')
-                    tme = datetime.now() - start
-                    if tme.seconds > 5:
-                        break
-                if self.mediaState:
-                    service_item.media_length = self.mediaLength
-                    service_item.add_capability(
-                        ItemCapabilities.AllowsVariableStartTime)
-            service_item.add_from_command(path, name, frame)
-            return True
-        else:
+        if not os.path.exists(filename):
             # File is no longer present
             critical_error_message_box(
                 translate('MediaPlugin.MediaItem', 'Missing Media File'),
                 unicode(translate('MediaPlugin.MediaItem',
                 'The file %s no longer exists.')) % filename)
             return False
+        self.mediaObject.stop()
+        self.mediaObject.clearQueue()
+        self.mediaObject.setCurrentSource(Phonon.MediaSource(filename))
+        if not self.mediaStateWait(Phonon.StoppedState):
+            # Due to string freeze, borrow a message from presentations
+            # This will be corrected in 1.9.6
+            critical_error_message_box(
+                translate('PresentationPlugin.MediaItem', 'Unsupported File'),
+                unicode(translate('PresentationPlugin.MediaItem', 
+                'Unsupported File')))
+            return False
+        # File too big for processing
+        if os.path.getsize(filename) <= 52428800: # 50MiB
+            self.mediaObject.play()
+            if not self.mediaStateWait(Phonon.PlayingState) \
+                or self.mediaObject.currentSource().type() \
+                == Phonon.MediaSource.Invalid:
+                # Due to string freeze, borrow a message from presentations
+                # This will be corrected in 1.9.6
+                self.mediaObject.stop()
+                critical_error_message_box(
+                    translate('PresentationPlugin.MediaItem', 
+                    'Unsupported File'),
+                    unicode(translate('PresentationPlugin.MediaItem',
+                    'Unsupported File')))
+                return False
+            self.mediaLength = self.mediaObject.totalTime() / 1000
+            self.mediaObject.stop()
+            service_item.media_length = self.mediaLength
+            service_item.add_capability(
+                ItemCapabilities.AllowsVariableStartTime)
+        service_item.title = unicode(self.plugin.nameStrings[u'singular'])
+        service_item.add_capability(ItemCapabilities.RequiresMedia)
+        # force a non-existent theme
+        service_item.theme = -1
+        frame = u':/media/image_clapperboard.png'
+        (path, name) = os.path.split(filename)
+        service_item.add_from_command(path, name, frame)
+        return True
 
+    def mediaStateWait(self, mediaState):
+        """
+        Wait for the video to change its state
+        Wait no longer than 5 seconds. 
+        """
+        start = datetime.now()
+        while self.mediaObject.state() != mediaState:
+            if self.mediaObject.state() == Phonon.ErrorState:
+                return False
+            Receiver.send_message(u'openlp_process_events')
+            if (datetime.now() - start).seconds > 5:
+                return False
+        return True
+        
     def initialise(self):
         self.listView.clear()
         self.listView.setIconSize(QtCore.QSize(88, 50))
@@ -187,12 +210,3 @@
             item_name.setIcon(build_icon(img))
             item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file))
             self.listView.addItem(item_name)
-
-    def videoStart(self, newState, oldState):
-        """
-        Start the video at a predetermined point.
-        """
-        if newState == Phonon.PlayingState:
-            self.mediaState = newState
-            self.mediaLength = self.mediaObject.totalTime()/1000
-            self.mediaObject.stop()


Follow ups