Refactor video length

This commit is contained in:
Tim Bentley 2012-09-09 07:54:09 +01:00
parent 6ef5fa88d2
commit 1df6934bda
2 changed files with 61 additions and 29 deletions

View File

@ -356,6 +356,37 @@ class MediaController(object):
log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display]) log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display])
return True return True
def media_length(self, controller, service_item):
"""
Loads and starts a video to run with the option of sound
"""
print controller
log.debug(u'media_length')
# stop running videos
self.video_reset(controller)
controller.media_info = MediaInfo()
controller.media_info.volume = controller.volumeSlider.value()
controller.media_info.file_info = QtCore.QFileInfo(service_item
.get_filename())
display = controller.previewDisplay
if not self.check_file_type(controller, display):
# Media could not be loaded correctly
critical_error_message_box(
translate('MediaPlugin.MediaItem', 'Unsupported File'),
unicode(translate('MediaPlugin.MediaItem',
'Unsupported File')))
return False
# set a black background by default no theme is needed.
if not self.video_play([controller]):
critical_error_message_box(
translate('MediaPlugin.MediaItem', 'Unsupported File'),
unicode(translate('MediaPlugin.MediaItem',
'Unsupported File')))
return False
self.video_stop([controller])
log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display])
return True
def check_file_type(self, controller, display): def check_file_type(self, controller, display):
""" """
Select the correct media Player type from the prioritized Player list Select the correct media Player type from the prioritized Player list

View File

@ -35,6 +35,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \ from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
SettingsManager, translate, check_item_selected, Receiver, MediaType, \ SettingsManager, translate, check_item_selected, Receiver, MediaType, \
ServiceItem, build_html ServiceItem, build_html
from openlp.core.lib.settings import Settings
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
create_horizontal_adjusting_combo_box create_horizontal_adjusting_combo_box
from openlp.core.ui import Controller, Display from openlp.core.ui import Controller, Display
@ -63,11 +64,11 @@ class MediaMediaItem(MediaManagerItem):
self.mediaObject = None self.mediaObject = None
self.mediaController = Controller(parent) self.mediaController = Controller(parent)
self.mediaController.controllerLayout = QtGui.QVBoxLayout() self.mediaController.controllerLayout = QtGui.QVBoxLayout()
self.plugin.mediaController.add_controller_items(self.mediaController, \ self.plugin.mediaController.add_controller_items(self.mediaController,
self.mediaController.controllerLayout) self.mediaController.controllerLayout)
self.plugin.mediaController.set_controls_visible(self.mediaController, \ self.plugin.mediaController.set_controls_visible(self.mediaController,
False) False)
self.mediaController.previewDisplay = Display(self.mediaController, \ self.mediaController.previewDisplay = Display(self.mediaController,
False, self.mediaController) False, self.mediaController)
self.mediaController.previewDisplay.setGeometry( self.mediaController.previewDisplay.setGeometry(
QtCore.QRect(0, 0, 300, 300)) QtCore.QRect(0, 0, 300, 300))
@ -75,11 +76,11 @@ class MediaMediaItem(MediaManagerItem):
{u'size':self.mediaController.previewDisplay.geometry()} {u'size':self.mediaController.previewDisplay.geometry()}
self.mediaController.previewDisplay.setup() self.mediaController.previewDisplay.setup()
serviceItem = ServiceItem() serviceItem = ServiceItem()
self.mediaController.previewDisplay.webView.setHtml(build_html( \ self.mediaController.previewDisplay.webView.setHtml(build_html(
serviceItem, self.mediaController.previewDisplay.screen, None, \ serviceItem, self.mediaController.previewDisplay.screen, None,
False, None)) False, None))
self.mediaController.previewDisplay.setup() self.mediaController.previewDisplay.setup()
self.plugin.mediaController.setup_display( \ self.plugin.mediaController.setup_display(
self.mediaController.previewDisplay) self.mediaController.previewDisplay)
self.mediaController.previewDisplay.hide() self.mediaController.previewDisplay.hide()
@ -154,7 +155,7 @@ class MediaMediaItem(MediaManagerItem):
""" """
Called to reset the Live background with the media selected, Called to reset the Live background with the media selected,
""" """
self.plugin.liveController.mediaController.video_reset( \ self.plugin.liveController.mediaController.video_reset(
self.plugin.liveController) self.plugin.liveController)
self.resetAction.setVisible(False) self.resetAction.setVisible(False)
@ -174,7 +175,7 @@ class MediaMediaItem(MediaManagerItem):
item = self.listView.currentItem() item = self.listView.currentItem()
filename = unicode(item.data(QtCore.Qt.UserRole).toString()) filename = unicode(item.data(QtCore.Qt.UserRole).toString())
if os.path.exists(filename): if os.path.exists(filename):
if self.plugin.liveController.mediaController.video( \ if self.plugin.liveController.mediaController.video(
self.plugin.liveController, filename, True, True): self.plugin.liveController, filename, True, True):
self.resetAction.setVisible(True) self.resetAction.setVisible(True)
else: else:
@ -188,7 +189,7 @@ class MediaMediaItem(MediaManagerItem):
'the media file "%s" no longer exists.')) % filename) 'the media file "%s" no longer exists.')) % filename)
def generateSlideData(self, service_item, item=None, xmlVersion=False, def generateSlideData(self, service_item, item=None, xmlVersion=False,
remote=False): remote=False):
if item is None: if item is None:
item = self.listView.currentItem() item = self.listView.currentItem()
if item is None: if item is None:
@ -199,28 +200,28 @@ class MediaMediaItem(MediaManagerItem):
# File is no longer present # File is no longer present
critical_error_message_box( critical_error_message_box(
translate('MediaPlugin.MediaItem', 'Missing Media File'), translate('MediaPlugin.MediaItem', 'Missing Media File'),
unicode(translate('MediaPlugin.MediaItem', unicode(translate('MediaPlugin.MediaItem',
'The file %s no longer exists.')) % filename) 'The file %s no longer exists.')) % filename)
return False return False
self.mediaLength = 0 self.mediaLength = 0
if self.plugin.mediaController.video( \ service_item.title = unicode(self.displayTypeComboBox.currentText())
self.mediaController, filename, False, False): service_item.shortname = service_item.title
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)
else:
return False
service_item.media_length = self.mediaLength
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) (path, name) = os.path.split(filename)
service_item.add_from_command(path, name, frame) service_item.add_from_command(path, name,
u':/media/image_clapperboard.png')
# Start media and obtain the length
if not self.plugin.mediaController.media_length(
self.mediaController, service_item):
return False
service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
service_item.add_capability(ItemCapabilities.RequiresMedia)
if Settings().value(self.settingsSection + u'/media auto start',
QtCore.QVariant(QtCore.Qt.Unchecked)).toInt()[0]\
== QtCore.Qt.Checked:
service_item.will_auto_start = True
# force a non-existent theme
service_item.theme = -1
return True return True
def initialise(self): def initialise(self):
@ -241,7 +242,7 @@ class MediaMediaItem(MediaManagerItem):
u' '.join(self.plugin.audio_extensions_list), UiStrings().AllFiles) u' '.join(self.plugin.audio_extensions_list), UiStrings().AllFiles)
def displaySetup(self): def displaySetup(self):
self.plugin.mediaController.setup_display( \ self.plugin.mediaController.setup_display(
self.mediaController.previewDisplay) self.mediaController.previewDisplay)
def populateDisplayTypes(self): def populateDisplayTypes(self):