From 1c63ef3ea1b88d3170b5739d1e58f0708683fea8 Mon Sep 17 00:00:00 2001 From: "rimach crichter@web.de" Date: Mon, 25 Jul 2011 22:56:39 +0200 Subject: [PATCH] add starttime for python and vlc --- openlp/core/ui/__init__.py | 2 +- openlp/core/ui/media/mediamanager.py | 6 ++++-- openlp/core/ui/media/phononapi.py | 24 ++++++++++++++---------- openlp/core/ui/media/vlcapi.py | 23 ++++++++++++++++++----- openlp/core/ui/media/webkitapi.py | 4 ++++ openlp/plugins/media/lib/mediaitem.py | 22 +++++++++++++++++++--- 6 files changed, 60 insertions(+), 21 deletions(-) diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index 543adaa77..0d0813a9b 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -61,7 +61,7 @@ from screen import ScreenList from maindisplay import MainDisplay, Display from servicenoteform import ServiceNoteForm from serviceitemeditform import ServiceItemEditForm -from slidecontroller import SlideController +from slidecontroller import SlideController, Controller from splashscreen import SplashScreen from generaltab import GeneralTab from themestab import ThemesTab diff --git a/openlp/core/ui/media/mediamanager.py b/openlp/core/ui/media/mediamanager.py index f83b62cd6..8a2bca04c 100644 --- a/openlp/core/ui/media/mediamanager.py +++ b/openlp/core/ui/media/mediamanager.py @@ -268,14 +268,16 @@ class MediaManager(object): controller.media_info.file_info = QtCore.QFileInfo(file) controller.media_info.is_background = isBackground if controller.isLive: - if self.withLivePreview: + if self.withLivePreview and controller.previewDisplay: display = controller.previewDisplay isValid = self.check_file_type(controller, display) display = controller.display isValid = self.check_file_type(controller, display) display.override[u'theme'] = u'' display.override[u'video'] = True - else: + controller.media_info.start_time = display.serviceItem.start_time + controller.media_info.end_time = display.serviceItem.end_time + elif controller.previewDisplay: display = controller.previewDisplay isValid = self.check_file_type(controller, display) if not isValid: diff --git a/openlp/core/ui/media/phononapi.py b/openlp/core/ui/media/phononapi.py index df3f4cc5f..78c44e946 100644 --- a/openlp/core/ui/media/phononapi.py +++ b/openlp/core/ui/media/phononapi.py @@ -155,12 +155,22 @@ class PhononAPI(MediaAPI): display.phononWidget.resize(display.size()) def play(self, display): - self.set_visible(display, True) controller = display.controller + start_time = 0 vol = float(controller.media_info.volume) / float(10) - display.audio.setVolume(vol) + if display.mediaObject.state() != Phonon.PausedState and \ + controller.media_info.start_time > 0: + start_time = controller.media_info.start_time display.mediaObject.play() - self.state = MediaState.Playing + if self.mediaStateWait(display, Phonon.PlayingState): + if start_time > 0: + self.seek(display, controller.media_info.start_time*1000) + display.audio.setVolume(vol) + controller.media_info.length = \ + int(display.mediaObject.totalTime()/1000) + controller.seekSlider.setMaximum(controller.media_info.length*1000) + self.state = MediaState.Playing + self.set_visible(display, True) def pause(self, display): display.mediaObject.pause() @@ -193,15 +203,9 @@ class PhononAPI(MediaAPI): def update_ui(self, display): controller = display.controller - controller.media_info.length = display.mediaObject.totalTime() - controller.seekSlider.setMaximum(controller.media_info.length) - if controller.media_info.start_time > 0: - if display.mediaObject.currentTime() < \ - controller.media_info.start_time: - self.seek(display, controller.media_info.start_time) if controller.media_info.end_time > 0: if display.mediaObject.currentTime() > \ - controller.media_info.end_time: + controller.media_info.end_time*1000: self.stop(display) self.set_visible(display, False) if not controller.seekSlider.isSliderDown(): diff --git a/openlp/core/ui/media/vlcapi.py b/openlp/core/ui/media/vlcapi.py index 41dff39e8..0af89438d 100644 --- a/openlp/core/ui/media/vlcapi.py +++ b/openlp/core/ui/media/vlcapi.py @@ -138,10 +138,19 @@ class VlcAPI(MediaAPI): display.vlcWidget.resize(display.size()) def play(self, display): - self.set_visible(display, True) + controller = display.controller + start_time = 0 + if controller.media_info.start_time > 0: + start_time = controller.media_info.start_time display.vlcMediaPlayer.play() if self.mediaStateWait(display, vlc.State.Playing): + if start_time > 0: + self.seek(display, controller.media_info.start_time*1000) + controller.media_info.length = \ + int(display.vlcMediaPlayer.get_media().get_duration()/1000) + controller.seekSlider.setMaximum(controller.media_info.length*1000) self.state = MediaState.Playing + self.set_visible(display, True) def pause(self, display): if display.vlcMedia.get_state() != vlc.State.Playing: @@ -160,7 +169,7 @@ class VlcAPI(MediaAPI): def seek(self, display, seekVal): if display.vlcMediaPlayer.is_seekable(): - display.vlcMediaPlayer.set_position(seekVal/1000.0) + display.vlcMediaPlayer.set_time(seekVal) def reset(self, display): display.vlcMediaPlayer.stop() @@ -173,7 +182,11 @@ class VlcAPI(MediaAPI): def update_ui(self, display): controller = display.controller - controller.seekSlider.setMaximum(1000) + if controller.media_info.end_time > 0: + if display.vlcMediaPlayer.get_time() > \ + controller.media_info.end_time*1000: + self.stop(display) + self.set_visible(display, False) if not controller.seekSlider.isSliderDown(): - currentPos = display.vlcMediaPlayer.get_position() * 1000 - controller.seekSlider.setSliderPosition(currentPos) + controller.seekSlider.setSliderPosition( \ + display.vlcMediaPlayer.get_time()) diff --git a/openlp/core/ui/media/webkitapi.py b/openlp/core/ui/media/webkitapi.py index e8cd40054..74f52380d 100644 --- a/openlp/core/ui/media/webkitapi.py +++ b/openlp/core/ui/media/webkitapi.py @@ -300,11 +300,14 @@ class WebkitAPI(MediaAPI): def play(self, display): controller = display.controller display.webLoaded = True + length = 0 self.set_visible(display, True) if controller.media_info.isFlash: display.frame.evaluateJavaScript(u'show_flash("play");') else: display.frame.evaluateJavaScript(u'show_video("play");') + #TODO add playing check and get the correct media length + controller.media_info.length = length self.state = MediaState.Playing def pause(self, display): @@ -374,6 +377,7 @@ class WebkitAPI(MediaAPI): if ok and length == length: length = int(length*1000) if currentTime > 0: + controller.media_info.length = length controller.seekSlider.setMaximum(length) if not controller.seekSlider.isSliderDown(): controller.seekSlider.setSliderPosition(currentTime) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 3e56aa537..217b4e553 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -34,6 +34,7 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \ SettingsManager, translate, check_item_selected, Receiver from openlp.core.lib.ui import UiStrings, critical_error_message_box +from openlp.core.ui import Controller, Display log = logging.getLogger(__name__) @@ -52,6 +53,15 @@ class MediaMediaItem(MediaManagerItem): self.singleServiceItem = False self.hasSearch = True self.mediaObject = None + self.mediaController = Controller(parent) + self.mediaController.controllerLayout = QtGui.QVBoxLayout() + self.plugin.mediaManager.addControllerItems(self.mediaController, self.mediaController.controllerLayout) + self.plugin.mediaManager.set_controls_visible(self.mediaController, False) + self.mediaController.previewDisplay = Display(self.mediaController, False, self.mediaController, self.plugin.pluginManager.plugins) + self.mediaController.previewDisplay.setup() + self.plugin.mediaManager.setup_display(self.mediaController.previewDisplay) + self.mediaController.previewDisplay.hide() + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'video_background_replaced'), self.videobackgroundReplaced) @@ -137,10 +147,16 @@ class MediaMediaItem(MediaManagerItem): 'The file %s no longer exists.')) % filename) return False self.mediaLength = 0 + if self.plugin.mediaManager.video( \ + self.mediaController, filename, False, False): + self.mediaLength = self.mediaController.media_info.length + service_item.media_length = self.mediaLength + self.plugin.mediaManager.video_reset(self.mediaController) + if self.mediaLength > 0: + service_item.add_capability( + ItemCapabilities.AllowsVariableStartTime) + print self.mediaLength service_item.media_length = self.mediaLength - #TODO - #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