← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~mzibricky/openlp/bug-963955 into lp:openlp

 

matysek has proposed merging lp:~mzibricky/openlp/bug-963955 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #963955 in OpenLP: "VLC backend for Mac OS X"
  https://bugs.launchpad.net/openlp/+bug/963955

For more details, see:
https://code.launchpad.net/~mzibricky/openlp/bug-963955/+merge/131750

This is the fix for playback with vlc on osx. It also includes fix to get media length without starting playback of a video.

I tested it only on osx in one- and dual-screen setup so far.
-- 
https://code.launchpad.net/~mzibricky/openlp/bug-963955/+merge/131750
Your team OpenLP Core is requested to review the proposed merge of lp:~mzibricky/openlp/bug-963955 into lp:openlp.
=== modified file 'openlp/core/ui/media/mediacontroller.py'
--- openlp/core/ui/media/mediacontroller.py	2012-10-21 14:07:57 +0000
+++ openlp/core/ui/media/mediacontroller.py	2012-10-27 18:19:22 +0000
@@ -107,11 +107,6 @@
             AppLocation.get_directory(AppLocation.AppDir),
             u'core', u'ui', u'media')
         for filename in os.listdir(controller_dir):
-            # TODO vlc backend is not yet working on Mac OS X.
-            # For now just ignore vlc backend on Mac OS X.
-            if sys.platform == 'darwin' and filename == 'vlcplayer.py':
-                log.warn(u'Disabling vlc media player')
-                continue
             if filename.endswith(u'player.py'):
                 path = os.path.join(controller_dir, filename)
                 if os.path.isfile(path):
@@ -150,13 +145,18 @@
         if not self.curDisplayMediaPlayer.keys():
             self.timer.stop()
         else:
+            any_active = False
             for display in self.curDisplayMediaPlayer.keys():
                 self.curDisplayMediaPlayer[display].resize(display)
                 self.curDisplayMediaPlayer[display].update_ui(display)
                 if self.curDisplayMediaPlayer[display].state == \
-                    MediaState.Playing:
-                    return
-        # no players are active anymore
+                        MediaState.Playing:
+                    any_active = True
+            # There are still any active players - no need to stop timer.
+            if any_active:
+                return
+
+        # No players are active anymore.
         for display in self.curDisplayMediaPlayer.keys():
             if self.curDisplayMediaPlayer[display].state != MediaState.Paused:
                 display.controller.seekSlider.setSliderPosition(0)
@@ -295,7 +295,8 @@
         """
         player.resize(display)
 
-    def video(self, controller, file, muted, isBackground, hidden=False):
+    def video(self, controller, file, muted, isBackground, hidden=False,
+            isInfo=False, controllersVisible=True):
         """
         Loads and starts a video to run with the option of sound
         """
@@ -353,14 +354,16 @@
         elif Settings().value(u'general/auto unblank',
             QtCore.QVariant(False)).toBool():
             autoplay = True
-        if autoplay:
+        # Start playback only for visible widgets. If we need just load a video
+        # and get video information, do not start playback.
+        if autoplay and not isInfo:
             if not self.video_play([controller]):
                 critical_error_message_box(
                     translate('MediaPlugin.MediaItem', 'Unsupported File'),
                     unicode(translate('MediaPlugin.MediaItem',
                     'Unsupported File')))
                 return False
-        self.set_controls_visible(controller, True)
+        self.set_controls_visible(controller, controllersVisible)
         log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display])
         return True
 

=== modified file 'openlp/core/ui/media/phononplayer.py'
--- openlp/core/ui/media/phononplayer.py	2012-10-21 14:07:57 +0000
+++ openlp/core/ui/media/phononplayer.py	2012-10-27 18:19:22 +0000
@@ -53,7 +53,7 @@
         u'video/x-matroska': [u'.mpv', u'.mkv'],
         u'video/x-wmv': [u'.wmv'],
         u'video/x-mpg': [u'.mpg'],
-        u'video/mpeg' : [u'.mp4', u'.mts'],
+        u'video/mpeg' : [u'.mp4', u'.mts', u'.mov'],
         u'video/x-ms-wmv': [u'.wmv']}
 
 

=== modified file 'openlp/core/ui/media/vlcplayer.py'
--- openlp/core/ui/media/vlcplayer.py	2012-10-21 14:07:57 +0000
+++ openlp/core/ui/media/vlcplayer.py	2012-10-27 18:19:22 +0000
@@ -124,18 +124,21 @@
         display.vlcWidget.resize(display.size())
         display.vlcWidget.raise_()
         display.vlcWidget.hide()
-        # the media player has to be 'connected' to the QFrame
+        # The media player has to be 'connected' to the QFrame.
         # (otherwise a video would be displayed in it's own window)
-        # this is platform specific!
-        # you have to give the id of the QFrame (or similar object) to
-        # vlc, different platforms have different functions for this
+        # This is platform specific!
+        # You have to give the id of the QFrame (or similar object)
+        # to vlc, different platforms have different functions for this.
+        win_id = int(display.vlcWidget.winId())
         if sys.platform == "win32":
-            display.vlcMediaPlayer.set_hwnd(int(display.vlcWidget.winId()))
+            display.vlcMediaPlayer.set_hwnd(win_id)
         elif sys.platform == "darwin":
-            display.vlcMediaPlayer.set_agl(int(display.vlcWidget.winId()))
+            # We have to use 'set_nsobject' since Qt4 on OSX uses Cocoa
+            # framework and not the old Carbon.
+            display.vlcMediaPlayer.set_nsobject(win_id)
         else:
             # for Linux using the X Server
-            display.vlcMediaPlayer.set_xwindow(int(display.vlcWidget.winId()))
+            display.vlcMediaPlayer.set_xwindow(win_id)
         self.hasOwnWidget = True
 
     def check_available(self):
@@ -155,6 +158,13 @@
         # parse the metadata of the file
         display.vlcMedia.parse()
         self.volume(display, volume)
+        # We need to set media_info.length during load because we want
+        # to avoid start and stop the video twice. Once for real playback
+        # and once to just get media length.
+        # 
+        # Media plugin depends on knowing media length before playback.
+        controller.media_info.length = \
+            int(display.vlcMediaPlayer.get_media().get_duration() / 1000)
         return True
 
     def media_state_wait(self, display, mediaState):
@@ -220,6 +230,7 @@
             display.vlcWidget.setVisible(status)
 
     def update_ui(self, display):
+        # Stop video if playback is finished.
         if display.vlcMedia.get_state() == vlc.State.Ended:
             self.stop(display)
         controller = display.controller

=== modified file 'openlp/plugins/media/lib/mediaitem.py'
--- openlp/plugins/media/lib/mediaitem.py	2012-10-21 14:07:57 +0000
+++ openlp/plugins/media/lib/mediaitem.py	2012-10-27 18:19:22 +0000
@@ -205,11 +205,20 @@
                             'The file %s no longer exists.')) % filename)
             return False
         self.mediaLength = 0
-        if self.plugin.mediaController.video( \
-                    self.mediaController, filename, False, False):
+        # Get media information and its length.
+        #
+        # This code (mediaController.video()) starts playback but we
+        # need only media information not video to start. Otherwise
+        # video is played twice. Find another way to get media info
+        # without loading and starting video playback.
+        #
+        # TODO Test getting media length with other media backends
+        # Phonon/Webkit.
+        if self.plugin.mediaController.video(self.mediaController,
+                    filename, muted=False, isBackground=False, isInfo=True,
+                    controllersVisible=False):
             self.mediaLength = self.mediaController.media_info.length
             service_item.media_length = self.mediaLength
-            self.plugin.mediaController.video_reset(self.mediaController)
             if self.mediaLength > 0:
                 service_item.add_capability(
                     ItemCapabilities.HasVariableStartTime)


Follow ups