From 15d031eec16e4b9895a0c90499b2ca1ba4167449 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sat, 18 Aug 2012 19:26:54 +0200 Subject: [PATCH 1/7] Fix playback of videos with vlc in preview window on OSX. --- openlp/core/ui/media/vlcplayer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/media/vlcplayer.py b/openlp/core/ui/media/vlcplayer.py index bf1e7a920..287b06a80 100644 --- a/openlp/core/ui/media/vlcplayer.py +++ b/openlp/core/ui/media/vlcplayer.py @@ -136,7 +136,9 @@ class VlcPlayer(MediaPlayer): if sys.platform == "win32": display.vlcMediaPlayer.set_hwnd(int(display.vlcWidget.winId())) 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(int(display.vlcWidget.winId())) else: # for Linux using the X Server display.vlcMediaPlayer.set_xwindow(int(display.vlcWidget.winId())) @@ -215,9 +217,11 @@ class VlcPlayer(MediaPlayer): display.vlcMediaPlayer.set_time(seekVal) def reset(self, display): - display.vlcMediaPlayer.stop() - display.vlcWidget.setVisible(False) - self.state = MediaState.Off + # FIXME Reset causes that OpenLP stops responding on OS X. + #display.vlcMediaPlayer.stop() + #display.vlcWidget.setVisible(False) + #self.state = MediaState.Off + pass def set_visible(self, display, status): if self.hasOwnWidget: From e1cd3bdd8b43866f6790548744b8054b9459a3ea Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sun, 21 Oct 2012 22:42:51 +0200 Subject: [PATCH 2/7] Allow .mov videos in phonon backend. --- openlp/core/ui/media/phononplayer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/media/phononplayer.py b/openlp/core/ui/media/phononplayer.py index 94865d16b..a7e2dc43c 100644 --- a/openlp/core/ui/media/phononplayer.py +++ b/openlp/core/ui/media/phononplayer.py @@ -52,7 +52,7 @@ ADDITIONAL_EXT = { 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']} From b5de3c28289828ca6807428338955a5b120d3336 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sat, 27 Oct 2012 16:52:51 +0200 Subject: [PATCH 3/7] Bug #963955: Avoid the need to start video twice to just get media length. --- openlp/core/ui/media/mediacontroller.py | 14 ++++---- openlp/core/ui/media/vlcplayer.py | 47 ++++++++++++++----------- openlp/plugins/media/lib/mediaitem.py | 12 +++++-- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index d56538331..e267c3a46 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -106,11 +106,6 @@ class MediaController(object): 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): @@ -294,7 +289,8 @@ class MediaController(object): """ 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 """ @@ -352,14 +348,16 @@ class MediaController(object): 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 diff --git a/openlp/core/ui/media/vlcplayer.py b/openlp/core/ui/media/vlcplayer.py index 79710c2aa..c2a37144e 100644 --- a/openlp/core/ui/media/vlcplayer.py +++ b/openlp/core/ui/media/vlcplayer.py @@ -110,33 +110,35 @@ class VlcPlayer(MediaPlayer): display.vlcWidget = QtGui.QFrame(display) # creating a basic vlc instance command_line_options = u'--no-video-title-show' - if not display.hasAudio: - command_line_options += u' --no-audio --no-video-title-show' - if Settings().value(u'advanced/hide mouse', - QtCore.QVariant(False)).toBool() and \ - display.controller.isLive: - command_line_options += u' --mouse-hide-timeout=0' - display.vlcInstance = vlc.Instance(command_line_options) - display.vlcInstance.set_log_verbosity(2) + #if not display.hasAudio: + #command_line_options += u' --no-audio --no-video-title-show' + #if Settings().value(u'advanced/hide mouse', + #QtCore.QVariant(False)).toBool() and \ + #display.controller.isLive: + #command_line_options += u' --mouse-hide-timeout=0' + #display.vlcInstance = vlc.Instance(command_line_options) + display.vlcInstance = vlc.get_default_instance() + #display.vlcInstance.set_log_verbosity(2) # creating an empty vlc media player display.vlcMediaPlayer = display.vlcInstance.media_player_new() 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": # We have to use 'set_nsobject' since Qt4 on OSX uses Cocoa # framework and not the old Carbon. - display.vlcMediaPlayer.set_nsobject(int(display.vlcWidget.winId())) + 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): @@ -156,6 +158,13 @@ class VlcPlayer(MediaPlayer): # 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): @@ -212,11 +221,9 @@ class VlcPlayer(MediaPlayer): display.vlcMediaPlayer.set_time(seekVal) def reset(self, display): - # FIXME Reset causes that OpenLP stops responding on OS X. - #display.vlcMediaPlayer.stop() - #display.vlcWidget.setVisible(False) - #self.state = MediaState.Off - pass + display.vlcMediaPlayer.stop() + display.vlcWidget.setVisible(False) + self.state = MediaState.Off def set_visible(self, display, status): if self.hasOwnWidget: diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 9f661149b..d1b0a8777 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -204,11 +204,19 @@ class MediaMediaItem(MediaManagerItem): 'The file %s no longer exists.')) % filename) return False self.mediaLength = 0 + # Get media information and its length. + # TODO 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, False, False): + self.mediaController, filename, muted=True, + 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) + print ' media length:', self.mediaLength if self.mediaLength > 0: service_item.add_capability( ItemCapabilities.HasVariableStartTime) From 4a68322a60390b8843cc20d6a1b3de0c7612c0b0 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sat, 27 Oct 2012 17:01:55 +0200 Subject: [PATCH 4/7] Bug #963955: Fix the video progress bar. --- openlp/plugins/media/lib/mediaitem.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index d1b0a8777..765e59cfc 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -205,18 +205,19 @@ class MediaMediaItem(MediaManagerItem): return False self.mediaLength = 0 # Get media information and its length. - # TODO 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. + # + # 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=True, - isBackground=False, isInfo=True, controllersVisible=False): + 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 - print ' media length:', self.mediaLength if self.mediaLength > 0: service_item.add_capability( ItemCapabilities.HasVariableStartTime) From e6cc675207d641fa3c8c01b12292a07781f60ecf Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sat, 27 Oct 2012 19:04:54 +0200 Subject: [PATCH 5/7] Bug #963955: Fix the video progress bar. --- openlp/core/ui/media/mediacontroller.py | 11 ++++++++--- openlp/core/ui/media/vlcplayer.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index e267c3a46..b0b7234a5 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -144,13 +144,18 @@ class MediaController(object): 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) diff --git a/openlp/core/ui/media/vlcplayer.py b/openlp/core/ui/media/vlcplayer.py index c2a37144e..e851b61b8 100644 --- a/openlp/core/ui/media/vlcplayer.py +++ b/openlp/core/ui/media/vlcplayer.py @@ -230,6 +230,7 @@ class VlcPlayer(MediaPlayer): 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 From 064a318f9ad89a4c7db4eade6531cc5e69b648d9 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sat, 27 Oct 2012 19:32:56 +0200 Subject: [PATCH 6/7] Bug #963955: Disable audio for video preview. --- openlp/core/ui/media/vlcplayer.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/openlp/core/ui/media/vlcplayer.py b/openlp/core/ui/media/vlcplayer.py index e851b61b8..4f233c666 100644 --- a/openlp/core/ui/media/vlcplayer.py +++ b/openlp/core/ui/media/vlcplayer.py @@ -110,15 +110,14 @@ class VlcPlayer(MediaPlayer): display.vlcWidget = QtGui.QFrame(display) # creating a basic vlc instance command_line_options = u'--no-video-title-show' - #if not display.hasAudio: - #command_line_options += u' --no-audio --no-video-title-show' - #if Settings().value(u'advanced/hide mouse', - #QtCore.QVariant(False)).toBool() and \ - #display.controller.isLive: - #command_line_options += u' --mouse-hide-timeout=0' - #display.vlcInstance = vlc.Instance(command_line_options) - display.vlcInstance = vlc.get_default_instance() - #display.vlcInstance.set_log_verbosity(2) + if not display.hasAudio: + command_line_options += u' --no-audio --no-video-title-show' + if Settings().value(u'advanced/hide mouse', + QtCore.QVariant(False)).toBool() and \ + display.controller.isLive: + command_line_options += u' --mouse-hide-timeout=0' + display.vlcInstance = vlc.Instance(command_line_options) + display.vlcInstance.set_log_verbosity(2) # creating an empty vlc media player display.vlcMediaPlayer = display.vlcInstance.media_player_new() display.vlcWidget.resize(display.size()) From 5c82a0c3dd9239703e9a8fbda757175023c8cca8 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Tue, 6 Nov 2012 12:58:32 +0100 Subject: [PATCH 7/7] Bug #963955 : Rename controllersVisible to controlsVisible. --- openlp/core/ui/media/mediacontroller.py | 4 ++-- openlp/plugins/media/lib/mediaitem.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index 1dc370f12..99102c3e1 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -296,7 +296,7 @@ class MediaController(object): player.resize(display) def video(self, controller, file, muted, isBackground, hidden=False, - isInfo=False, controllersVisible=True): + isInfo=False, controlsVisible=True): """ Loads and starts a video to run with the option of sound """ @@ -363,7 +363,7 @@ class MediaController(object): unicode(translate('MediaPlugin.MediaItem', 'Unsupported File'))) return False - self.set_controls_visible(controller, controllersVisible) + self.set_controls_visible(controller, controlsVisible) log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display]) return True diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 749fb1ebb..a47ebc36a 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -216,7 +216,7 @@ class MediaMediaItem(MediaManagerItem): # Phonon/Webkit. if self.plugin.mediaController.video(self.mediaController, filename, muted=False, isBackground=False, isInfo=True, - controllersVisible=False): + controlsVisible=False): self.mediaLength = self.mediaController.media_info.length service_item.media_length = self.mediaLength if self.mediaLength > 0: