2011-06-05 21:10:49 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2011 Raoul Snyman #
|
2011-06-14 16:10:20 +00:00
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan #
|
|
|
|
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
|
|
|
|
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
|
|
|
|
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
2011-06-05 21:10:49 +00:00
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
import logging
|
2011-12-02 21:13:05 +00:00
|
|
|
import os
|
|
|
|
from PyQt4 import QtCore, QtGui
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
from openlp.core.lib import OpenLPToolbar, Receiver, translate
|
2011-11-12 15:30:41 +00:00
|
|
|
from openlp.core.lib.mediaplayer import MediaPlayer
|
2011-12-02 21:13:05 +00:00
|
|
|
from openlp.core.lib.ui import critical_error_message_box
|
2011-11-11 16:45:25 +00:00
|
|
|
from openlp.core.ui.media import MediaState, MediaInfo, MediaType
|
2011-07-10 21:43:07 +00:00
|
|
|
from openlp.core.utils import AppLocation
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2011-08-29 21:51:03 +00:00
|
|
|
class MediaController(object):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-11-02 20:27:53 +00:00
|
|
|
The implementation of the Media Controller. The Media Controller adds an own
|
2011-11-11 16:45:25 +00:00
|
|
|
class for every Player. Currently these are QtWebkit, Phonon and planed Vlc.
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, parent):
|
|
|
|
self.parent = parent
|
2011-11-11 16:45:25 +00:00
|
|
|
self.mediaPlayers = {}
|
2011-06-05 21:10:49 +00:00
|
|
|
self.controller = []
|
2011-11-11 16:45:25 +00:00
|
|
|
self.overridenPlayer = ''
|
|
|
|
self.curDisplayMediaPlayer = {}
|
2011-08-29 19:55:58 +00:00
|
|
|
# Timer for video state
|
2011-09-22 18:22:35 +00:00
|
|
|
self.timer = QtCore.QTimer()
|
|
|
|
self.timer.setInterval(200)
|
2011-06-05 21:10:49 +00:00
|
|
|
self.withLivePreview = False
|
2011-11-11 16:45:25 +00:00
|
|
|
self.check_available_media_players()
|
2011-08-29 19:55:58 +00:00
|
|
|
# Signals
|
2011-09-22 18:22:35 +00:00
|
|
|
QtCore.QObject.connect(self.timer,
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.SIGNAL("timeout()"), self.video_state)
|
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2011-11-02 20:27:53 +00:00
|
|
|
QtCore.SIGNAL(u'media_playback_play'), self.video_play)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2011-11-02 20:27:53 +00:00
|
|
|
QtCore.SIGNAL(u'media_playback_pause'), self.video_pause)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2011-11-02 20:27:53 +00:00
|
|
|
QtCore.SIGNAL(u'media_playback_stop'), self.video_stop)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2011-11-02 20:27:53 +00:00
|
|
|
QtCore.SIGNAL(u'seek_slider'), self.video_seek)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2011-11-02 20:27:53 +00:00
|
|
|
QtCore.SIGNAL(u'volume_slider'), self.video_volume)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'media_hide'), self.video_hide)
|
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'media_blank'), self.video_blank)
|
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'media_unblank'), self.video_unblank)
|
2011-09-22 18:22:35 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2011-11-11 16:45:25 +00:00
|
|
|
QtCore.SIGNAL(u'media_override_player'), self.override_player)
|
2011-09-28 20:54:43 +00:00
|
|
|
# Signals for background video
|
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'songs_hide'), self.video_hide)
|
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'songs_unblank'), self.video_unblank)
|
2011-11-24 21:10:37 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'mediaitem_media_rebuild'), self.set_active_players)
|
|
|
|
|
|
|
|
def set_active_players(self):
|
|
|
|
playerSettings = str(QtCore.QSettings().value(u'media/players',
|
|
|
|
QtCore.QVariant(u'webkit')).toString())
|
2011-11-30 17:06:57 +00:00
|
|
|
if len(playerSettings) == 0:
|
|
|
|
playerSettings = u'webkit'
|
2011-11-24 21:10:37 +00:00
|
|
|
savedPlayers = playerSettings.split(u',')
|
2011-11-30 17:06:57 +00:00
|
|
|
for player in self.mediaPlayers.keys():
|
|
|
|
if player in savedPlayers:
|
|
|
|
self.mediaPlayers[player].isActive = True
|
|
|
|
else:
|
|
|
|
self.mediaPlayers[player].isActive = False
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2011-08-29 19:55:58 +00:00
|
|
|
def register_controllers(self, controller):
|
2011-07-10 21:43:07 +00:00
|
|
|
"""
|
2011-11-24 21:10:37 +00:00
|
|
|
Register each media Player controller (Webkit, Phonon, etc) and store
|
|
|
|
for later use
|
2011-07-10 21:43:07 +00:00
|
|
|
"""
|
|
|
|
if controller.check_available():
|
2011-11-11 16:45:25 +00:00
|
|
|
self.mediaPlayers[controller.name] = controller
|
2011-07-10 21:43:07 +00:00
|
|
|
|
2011-11-11 16:45:25 +00:00
|
|
|
def check_available_media_players(self):
|
2011-07-10 21:43:07 +00:00
|
|
|
"""
|
2011-11-24 21:10:37 +00:00
|
|
|
Check to see if we have any media Player's available. If Not do not
|
|
|
|
install the plugin.
|
2011-07-10 21:43:07 +00:00
|
|
|
"""
|
2011-11-11 16:45:25 +00:00
|
|
|
log.debug(u'check_available_media_players')
|
2011-07-10 21:43:07 +00:00
|
|
|
controller_dir = os.path.join(
|
|
|
|
AppLocation.get_directory(AppLocation.AppDir),
|
|
|
|
u'core', u'ui', u'media')
|
|
|
|
for filename in os.listdir(controller_dir):
|
2011-11-11 16:45:25 +00:00
|
|
|
if filename.endswith(u'player.py') and \
|
|
|
|
not filename == 'media_player.py':
|
2011-07-10 21:43:07 +00:00
|
|
|
path = os.path.join(controller_dir, filename)
|
|
|
|
if os.path.isfile(path):
|
|
|
|
modulename = u'openlp.core.ui.media.' + \
|
|
|
|
os.path.splitext(filename)[0]
|
|
|
|
log.debug(u'Importing controller %s', modulename)
|
|
|
|
try:
|
|
|
|
__import__(modulename, globals(), locals(), [])
|
|
|
|
except ImportError:
|
|
|
|
log.warn(u'Failed to import %s on path %s',
|
|
|
|
modulename, path)
|
2011-11-11 16:45:25 +00:00
|
|
|
controller_classes = MediaPlayer.__subclasses__()
|
2011-07-10 21:43:07 +00:00
|
|
|
for controller_class in controller_classes:
|
|
|
|
controller = controller_class(self)
|
2011-08-29 19:55:58 +00:00
|
|
|
self.register_controllers(controller)
|
2011-11-11 16:45:25 +00:00
|
|
|
if self.mediaPlayers:
|
|
|
|
playerSettings = str(QtCore.QSettings().value(u'media/players',
|
2011-11-02 20:27:53 +00:00
|
|
|
QtCore.QVariant(u'webkit')).toString())
|
2011-11-11 16:45:25 +00:00
|
|
|
savedPlayers = playerSettings.split(u',')
|
|
|
|
invalidMediaPlayers = [mediaPlayer for mediaPlayer in savedPlayers \
|
|
|
|
if not mediaPlayer in self.mediaPlayers]
|
2011-12-02 21:13:05 +00:00
|
|
|
if len(invalidMediaPlayers) > 0:
|
|
|
|
for invalidPlayer in invalidMediaPlayers:
|
|
|
|
savedPlayers.remove(invalidPlayer)
|
2011-11-11 16:45:25 +00:00
|
|
|
newPlayerSetting = u','.join(savedPlayers)
|
|
|
|
QtCore.QSettings().setValue(u'media/players',
|
|
|
|
QtCore.QVariant(newPlayerSetting))
|
2011-11-24 21:10:37 +00:00
|
|
|
self.set_active_players()
|
2011-07-10 21:43:07 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2011-06-05 21:10:49 +00:00
|
|
|
def video_state(self):
|
|
|
|
"""
|
2011-11-02 20:27:53 +00:00
|
|
|
Check if there is a running media Player and do updating stuff (e.g.
|
|
|
|
update the UI)
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-11-11 16:45:25 +00:00
|
|
|
if len(self.curDisplayMediaPlayer.keys()) == 0:
|
2011-09-22 18:22:35 +00:00
|
|
|
self.timer.stop()
|
2011-06-05 21:10:49 +00:00
|
|
|
else:
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
|
|
|
self.curDisplayMediaPlayer[display].resize(display)
|
|
|
|
self.curDisplayMediaPlayer[display].update_ui(display)
|
|
|
|
if self.curDisplayMediaPlayer[display] \
|
2011-06-05 21:10:49 +00:00
|
|
|
.state == MediaState.Playing:
|
2011-11-02 20:27:53 +00:00
|
|
|
return
|
|
|
|
self.timer.stop()
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2011-08-29 19:55:58 +00:00
|
|
|
def get_media_display_css(self):
|
2011-06-08 13:18:05 +00:00
|
|
|
"""
|
|
|
|
Add css style sheets to htmlbuilder
|
|
|
|
"""
|
2011-10-24 20:04:29 +00:00
|
|
|
css = u''
|
2011-11-11 16:45:25 +00:00
|
|
|
for player in self.mediaPlayers.values():
|
2011-11-24 21:10:37 +00:00
|
|
|
if player.isActive:
|
|
|
|
css += player.get_media_display_css()
|
2011-06-08 13:18:05 +00:00
|
|
|
return css
|
|
|
|
|
2011-08-29 19:55:58 +00:00
|
|
|
def get_media_display_javascript(self):
|
2011-06-08 13:18:05 +00:00
|
|
|
"""
|
|
|
|
Add javascript functions to htmlbuilder
|
|
|
|
"""
|
|
|
|
js = u''
|
2011-11-11 16:45:25 +00:00
|
|
|
for player in self.mediaPlayers.values():
|
2011-11-24 21:10:37 +00:00
|
|
|
if player.isActive:
|
|
|
|
js += player.get_media_display_javascript()
|
2011-06-08 13:18:05 +00:00
|
|
|
return js
|
|
|
|
|
2011-08-29 19:55:58 +00:00
|
|
|
def get_media_display_html(self):
|
2011-06-08 13:18:05 +00:00
|
|
|
"""
|
|
|
|
Add html code to htmlbuilder
|
|
|
|
"""
|
|
|
|
html = u''
|
2011-11-11 16:45:25 +00:00
|
|
|
for player in self.mediaPlayers.values():
|
2011-11-24 21:10:37 +00:00
|
|
|
if player.isActive:
|
|
|
|
html += player.get_media_display_html()
|
2011-06-08 13:18:05 +00:00
|
|
|
return html
|
|
|
|
|
2011-08-29 19:55:58 +00:00
|
|
|
def add_controller_items(self, controller, control_panel):
|
2011-06-05 21:10:49 +00:00
|
|
|
self.controller.append(controller)
|
|
|
|
self.setup_generic_controls(controller, control_panel)
|
2011-11-02 20:27:53 +00:00
|
|
|
self.setup_special_controls(controller, control_panel)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
def setup_generic_controls(self, controller, control_panel):
|
2011-11-02 20:27:53 +00:00
|
|
|
"""
|
|
|
|
Add generic media control items (valid for all types of medias)
|
|
|
|
"""
|
2011-06-05 21:10:49 +00:00
|
|
|
controller.media_info = MediaInfo()
|
|
|
|
# Build a Media ToolBar
|
|
|
|
controller.mediabar = OpenLPToolbar(controller)
|
|
|
|
controller.mediabar.addToolbarButton(
|
2011-11-02 20:27:53 +00:00
|
|
|
u'media_playback_play', u':/slides/media_playback_start.png',
|
2011-12-03 20:35:53 +00:00
|
|
|
translate('OpenLP.SlideController', 'Start playing media.'),
|
2011-06-05 21:10:49 +00:00
|
|
|
controller.sendToPlugins)
|
|
|
|
controller.mediabar.addToolbarButton(
|
2011-11-02 20:27:53 +00:00
|
|
|
u'media_playback_pause', u':/slides/media_playback_pause.png',
|
2011-12-03 20:35:53 +00:00
|
|
|
translate('OpenLP.SlideController', 'Pause playing media.'),
|
2011-06-05 21:10:49 +00:00
|
|
|
controller.sendToPlugins)
|
|
|
|
controller.mediabar.addToolbarButton(
|
2011-11-02 20:27:53 +00:00
|
|
|
u'media_playback_stop', u':/slides/media_playback_stop.png',
|
2011-12-03 20:35:53 +00:00
|
|
|
translate('OpenLP.SlideController', 'Stop playing media.'),
|
2011-06-05 21:10:49 +00:00
|
|
|
controller.sendToPlugins)
|
|
|
|
# Build the seekSlider.
|
|
|
|
controller.seekSlider = QtGui.QSlider(QtCore.Qt.Horizontal)
|
|
|
|
controller.seekSlider.setMaximum(1000)
|
2011-12-19 22:46:31 +00:00
|
|
|
controller.seekSlider.setTracking(False)
|
2011-10-17 21:35:44 +00:00
|
|
|
controller.seekSlider.setToolTip(translate(
|
|
|
|
'OpenLP.SlideController', 'Video position.'))
|
|
|
|
controller.seekSlider.setGeometry(QtCore.QRect(90, 260, 221, 24))
|
2011-11-02 20:27:53 +00:00
|
|
|
controller.seekSlider.setObjectName(u'seek_slider')
|
2011-12-03 20:35:53 +00:00
|
|
|
controller.mediabar.addToolbarWidget(u'Seek Slider',
|
2011-11-02 20:27:53 +00:00
|
|
|
controller.seekSlider)
|
2011-06-05 21:10:49 +00:00
|
|
|
# Build the volumeSlider.
|
|
|
|
controller.volumeSlider = QtGui.QSlider(QtCore.Qt.Horizontal)
|
|
|
|
controller.volumeSlider.setTickInterval(10)
|
|
|
|
controller.volumeSlider.setTickPosition(QtGui.QSlider.TicksAbove)
|
|
|
|
controller.volumeSlider.setMinimum(0)
|
|
|
|
controller.volumeSlider.setMaximum(100)
|
2011-12-19 22:46:31 +00:00
|
|
|
controller.volumeSlider.setTracking(True)
|
2011-10-17 21:35:44 +00:00
|
|
|
controller.volumeSlider.setToolTip(translate(
|
|
|
|
'OpenLP.SlideController', 'Audio Volume.'))
|
2011-06-05 21:10:49 +00:00
|
|
|
controller.volumeSlider.setValue(controller.media_info.volume)
|
|
|
|
controller.volumeSlider.setGeometry(QtCore.QRect(90, 160, 221, 24))
|
2011-11-02 20:27:53 +00:00
|
|
|
controller.volumeSlider.setObjectName(u'volume_slider')
|
2011-12-03 20:35:53 +00:00
|
|
|
controller.mediabar.addToolbarWidget(u'Audio Volume',
|
2011-11-02 20:27:53 +00:00
|
|
|
controller.volumeSlider)
|
2011-06-05 21:10:49 +00:00
|
|
|
control_panel.addWidget(controller.mediabar)
|
|
|
|
controller.mediabar.setVisible(False)
|
2011-08-29 19:55:58 +00:00
|
|
|
# Signals
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(controller.seekSlider,
|
2011-12-19 22:46:31 +00:00
|
|
|
QtCore.SIGNAL(u'valueChanged(int)'), controller.sendToPlugins)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(controller.volumeSlider,
|
2011-12-19 22:46:31 +00:00
|
|
|
QtCore.SIGNAL(u'valueChanged(int)'), controller.sendToPlugins)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2011-11-02 20:27:53 +00:00
|
|
|
def setup_special_controls(self, controller, control_panel):
|
|
|
|
"""
|
|
|
|
Special media Toolbars will be created here (e.g. for DVD Playback)
|
|
|
|
"""
|
|
|
|
controller.media_info = MediaInfo()
|
|
|
|
# TODO: add Toolbar for DVD, ...
|
|
|
|
|
2011-06-05 21:10:49 +00:00
|
|
|
def setup_display(self, display):
|
|
|
|
"""
|
2011-12-03 20:35:53 +00:00
|
|
|
After a new display is configured, all media related widget will be
|
2011-11-02 20:27:53 +00:00
|
|
|
created too
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-07-20 21:16:36 +00:00
|
|
|
# clean up possible running old media files
|
|
|
|
self.finalise()
|
2011-11-30 17:06:57 +00:00
|
|
|
# update player status
|
|
|
|
self.set_active_players()
|
2011-06-05 21:10:49 +00:00
|
|
|
display.hasAudio = True
|
|
|
|
if not self.withLivePreview and \
|
|
|
|
display == self.parent.liveController.previewDisplay:
|
|
|
|
return
|
|
|
|
if display == self.parent.previewController.previewDisplay or \
|
|
|
|
display == self.parent.liveController.previewDisplay:
|
|
|
|
display.hasAudio = False
|
2011-11-11 16:45:25 +00:00
|
|
|
for player in self.mediaPlayers.values():
|
2011-11-24 21:10:37 +00:00
|
|
|
if player.isActive:
|
|
|
|
player.setup(display)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
def set_controls_visible(self, controller, value):
|
|
|
|
# Generic controls
|
|
|
|
controller.mediabar.setVisible(value)
|
2011-12-03 20:35:53 +00:00
|
|
|
# Special controls: Here media type specific Controls will be enabled
|
2011-11-02 20:27:53 +00:00
|
|
|
# (e.g. for DVD control, ...)
|
2011-06-14 16:10:20 +00:00
|
|
|
# TODO
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2011-11-11 16:45:25 +00:00
|
|
|
def resize(self, controller, display, player):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-12-03 20:35:53 +00:00
|
|
|
After Mainwindow changes or Splitter moved all related media widgets
|
2011-11-02 20:27:53 +00:00
|
|
|
have to be resized
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-11-11 16:45:25 +00:00
|
|
|
player.resize(display)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2011-07-18 21:25:10 +00:00
|
|
|
def video(self, controller, file, muted, isBackground):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Loads and starts a video to run with the option of sound
|
|
|
|
"""
|
|
|
|
log.debug(u'video')
|
|
|
|
isValid = False
|
|
|
|
# stop running videos
|
|
|
|
self.video_reset(controller)
|
|
|
|
controller.media_info = MediaInfo()
|
2011-07-18 21:25:10 +00:00
|
|
|
if muted:
|
|
|
|
controller.media_info.volume = 0
|
|
|
|
else:
|
|
|
|
controller.media_info.volume = controller.volumeSlider.value()
|
|
|
|
controller.media_info.file_info = QtCore.QFileInfo(file)
|
|
|
|
controller.media_info.is_background = isBackground
|
2011-10-24 20:04:29 +00:00
|
|
|
display = None
|
2011-06-05 21:10:49 +00:00
|
|
|
if controller.isLive:
|
2011-07-25 20:56:39 +00:00
|
|
|
if self.withLivePreview and controller.previewDisplay:
|
2011-06-05 21:10:49 +00:00
|
|
|
display = controller.previewDisplay
|
2011-06-06 19:12:14 +00:00
|
|
|
isValid = self.check_file_type(controller, display)
|
2011-06-05 21:10:49 +00:00
|
|
|
display = controller.display
|
2011-06-06 19:12:14 +00:00
|
|
|
isValid = self.check_file_type(controller, display)
|
2011-07-20 21:16:36 +00:00
|
|
|
display.override[u'theme'] = u''
|
|
|
|
display.override[u'video'] = True
|
2011-12-06 21:42:34 +00:00
|
|
|
if controller.media_info.is_background:
|
|
|
|
# ignore start/end time
|
|
|
|
controller.media_info.start_time = 0
|
|
|
|
controller.media_info.end_time = 0
|
|
|
|
else:
|
|
|
|
controller.media_info.start_time = display.serviceItem.start_time
|
|
|
|
controller.media_info.end_time = display.serviceItem.end_time
|
2011-07-25 20:56:39 +00:00
|
|
|
elif controller.previewDisplay:
|
2011-06-05 21:10:49 +00:00
|
|
|
display = controller.previewDisplay
|
2011-06-06 19:12:14 +00:00
|
|
|
isValid = self.check_file_type(controller, display)
|
2011-06-05 21:10:49 +00:00
|
|
|
if not isValid:
|
2011-08-29 19:55:58 +00:00
|
|
|
# Media could not be loaded correctly
|
2011-06-05 21:10:49 +00:00
|
|
|
critical_error_message_box(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Unsupported File'),
|
|
|
|
unicode(translate('MediaPlugin.MediaItem',
|
|
|
|
'Unsupported File')))
|
2011-07-18 21:25:10 +00:00
|
|
|
return False
|
2011-11-24 21:10:37 +00:00
|
|
|
# dont care about actual theme, set a black background
|
|
|
|
if controller.isLive and ( \
|
|
|
|
controller.media_info.is_background == False):
|
|
|
|
display.frame.evaluateJavaScript(u'show_video( \
|
|
|
|
"setBackBoard", null, null, null,"visible");')
|
2011-08-29 19:55:58 +00:00
|
|
|
# now start playing
|
2011-12-01 18:07:15 +00:00
|
|
|
if controller.isLive and \
|
|
|
|
(QtCore.QSettings().value(u'general/auto unblank',
|
|
|
|
QtCore.QVariant(False)).toBool() or \
|
|
|
|
controller.media_info.is_background == True) or \
|
|
|
|
controller.isLive == False:
|
|
|
|
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)
|
|
|
|
log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display])
|
|
|
|
return True
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2011-06-06 19:12:14 +00:00
|
|
|
def check_file_type(self, controller, display):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-12-02 21:13:05 +00:00
|
|
|
Select the correct media Player type from the prioritized Player list
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-11-11 16:45:25 +00:00
|
|
|
playerSettings = str(QtCore.QSettings().value(u'media/players',
|
2011-11-02 20:27:53 +00:00
|
|
|
QtCore.QVariant(u'webkit')).toString())
|
2011-11-11 16:45:25 +00:00
|
|
|
usedPlayers = playerSettings.split(u',')
|
|
|
|
if QtCore.QSettings().value(u'media/override player',
|
2011-09-22 18:22:35 +00:00
|
|
|
QtCore.QVariant(QtCore.Qt.Unchecked)) == QtCore.Qt.Checked:
|
2011-11-11 16:45:25 +00:00
|
|
|
if self.overridenPlayer != '':
|
2011-12-02 21:33:11 +00:00
|
|
|
usedPlayers = [self.overridenPlayer]
|
2011-06-05 21:10:49 +00:00
|
|
|
if controller.media_info.file_info.isFile():
|
2011-12-02 21:13:05 +00:00
|
|
|
suffix = u'*.%s' % \
|
|
|
|
controller.media_info.file_info.suffix().toLower()
|
2011-11-11 16:45:25 +00:00
|
|
|
for title in usedPlayers:
|
|
|
|
player = self.mediaPlayers[title]
|
|
|
|
if suffix in player.video_extensions_list:
|
2011-06-05 21:10:49 +00:00
|
|
|
if not controller.media_info.is_background or \
|
2011-12-02 21:13:05 +00:00
|
|
|
controller.media_info.is_background and \
|
|
|
|
player.canBackground:
|
|
|
|
self.resize(controller, display, player)
|
|
|
|
if player.load(display):
|
|
|
|
self.curDisplayMediaPlayer[display] = player
|
|
|
|
controller.media_info.media_type = MediaType.Video
|
|
|
|
return True
|
2011-11-11 16:45:25 +00:00
|
|
|
if suffix in player.audio_extensions_list:
|
|
|
|
if player.load(display):
|
|
|
|
self.curDisplayMediaPlayer[display] = player
|
2011-08-29 19:55:58 +00:00
|
|
|
controller.media_info.media_type = MediaType.Audio
|
|
|
|
return True
|
2011-09-22 18:22:35 +00:00
|
|
|
else:
|
2011-11-11 16:45:25 +00:00
|
|
|
for title in usedPlayers:
|
|
|
|
player = self.mediaPlayers[title]
|
|
|
|
if player.canFolder:
|
|
|
|
self.resize(controller, display, player)
|
|
|
|
if player.load(display):
|
|
|
|
self.curDisplayMediaPlayer[display] = player
|
2011-09-22 18:22:35 +00:00
|
|
|
controller.media_info.media_type = MediaType.Video
|
|
|
|
return True
|
2011-11-11 16:45:25 +00:00
|
|
|
# no valid player found
|
2011-06-05 21:10:49 +00:00
|
|
|
return False
|
|
|
|
|
2011-09-28 20:54:43 +00:00
|
|
|
def video_play(self, msg, status=True):
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
Responds to the request to play a loaded video
|
2011-12-03 20:35:53 +00:00
|
|
|
|
2011-11-24 21:10:37 +00:00
|
|
|
``msg``
|
|
|
|
First element is the controller which should be used
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
log.debug(u'video_play')
|
|
|
|
controller = msg[0]
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-11-11 16:45:25 +00:00
|
|
|
if not self.curDisplayMediaPlayer[display].play(display):
|
2011-08-29 19:55:58 +00:00
|
|
|
return False
|
2011-09-28 20:54:43 +00:00
|
|
|
if status:
|
2011-11-30 17:06:57 +00:00
|
|
|
display.frame.evaluateJavaScript(u'show_blank("desktop");')
|
2011-12-02 21:13:05 +00:00
|
|
|
self.curDisplayMediaPlayer[display].set_visible(display,
|
|
|
|
True)
|
2011-11-24 21:10:37 +00:00
|
|
|
if controller.isLive:
|
|
|
|
if controller.hideMenu.defaultAction().isChecked():
|
|
|
|
controller.hideMenu.defaultAction().trigger()
|
2011-06-05 21:10:49 +00:00
|
|
|
# Start Timer for ui updates
|
2011-09-22 18:22:35 +00:00
|
|
|
if not self.timer.isActive():
|
|
|
|
self.timer.start()
|
2011-08-29 19:55:58 +00:00
|
|
|
return True
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
def video_pause(self, msg):
|
|
|
|
"""
|
|
|
|
Responds to the request to pause a loaded video
|
2011-11-24 21:10:37 +00:00
|
|
|
|
|
|
|
``msg``
|
|
|
|
First element is the controller which should be used
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-08-29 19:55:58 +00:00
|
|
|
log.debug(u'video_pause')
|
2011-06-05 21:10:49 +00:00
|
|
|
controller = msg[0]
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-11-11 16:45:25 +00:00
|
|
|
self.curDisplayMediaPlayer[display].pause(display)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
def video_stop(self, msg):
|
|
|
|
"""
|
|
|
|
Responds to the request to stop a loaded video
|
2011-11-24 21:10:37 +00:00
|
|
|
|
|
|
|
``msg``
|
|
|
|
First element is the controller which should be used
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
log.debug(u'video_stop')
|
|
|
|
controller = msg[0]
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-10-24 20:04:29 +00:00
|
|
|
display.frame.evaluateJavaScript(u'show_blank("black");')
|
2011-11-11 16:45:25 +00:00
|
|
|
self.curDisplayMediaPlayer[display].stop(display)
|
|
|
|
self.curDisplayMediaPlayer[display].set_visible(display, False)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
def video_volume(self, msg):
|
|
|
|
"""
|
|
|
|
Changes the volume of a running video
|
2011-11-24 21:10:37 +00:00
|
|
|
|
|
|
|
``msg``
|
|
|
|
First element is the controller which should be used
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
controller = msg[0]
|
2011-06-08 14:49:48 +00:00
|
|
|
vol = msg[1][0]
|
2011-06-05 21:10:49 +00:00
|
|
|
log.debug(u'video_volume %d' % vol)
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-11-11 16:45:25 +00:00
|
|
|
self.curDisplayMediaPlayer[display].volume(display, vol)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
def video_seek(self, msg):
|
|
|
|
"""
|
|
|
|
Responds to the request to change the seek Slider of a loaded video
|
2011-11-24 21:10:37 +00:00
|
|
|
|
|
|
|
``msg``
|
|
|
|
First element is the controller which should be used
|
|
|
|
Second element is a list with the seek Value as first element
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
log.debug(u'video_seek')
|
|
|
|
controller = msg[0]
|
2011-06-08 14:49:48 +00:00
|
|
|
seekVal = msg[1][0]
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-11-11 16:45:25 +00:00
|
|
|
self.curDisplayMediaPlayer[display].seek(display, seekVal)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
def video_reset(self, controller):
|
|
|
|
"""
|
|
|
|
Responds to the request to reset a loaded video
|
|
|
|
"""
|
|
|
|
log.debug(u'video_reset')
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-07-20 21:16:36 +00:00
|
|
|
display.override = {}
|
2011-11-11 16:45:25 +00:00
|
|
|
self.curDisplayMediaPlayer[display].reset(display)
|
|
|
|
self.curDisplayMediaPlayer[display].set_visible(display, False)
|
2011-11-02 20:27:53 +00:00
|
|
|
display.frame.evaluateJavaScript(u'show_video( \
|
|
|
|
"setBackBoard", null, null, null,"hidden");')
|
2011-11-11 16:45:25 +00:00
|
|
|
del self.curDisplayMediaPlayer[display]
|
2011-06-05 21:10:49 +00:00
|
|
|
self.set_controls_visible(controller, False)
|
|
|
|
|
|
|
|
def video_hide(self, msg):
|
|
|
|
"""
|
|
|
|
Hide the related video Widget
|
2011-11-24 21:10:37 +00:00
|
|
|
|
|
|
|
``msg``
|
|
|
|
First element is the boolean for Live indication
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
isLive = msg[1]
|
|
|
|
if isLive:
|
|
|
|
controller = self.parent.liveController
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-11-11 16:45:25 +00:00
|
|
|
if self.curDisplayMediaPlayer[display] \
|
2011-06-05 21:10:49 +00:00
|
|
|
.state == MediaState.Playing:
|
2011-11-11 16:45:25 +00:00
|
|
|
self.curDisplayMediaPlayer[display].pause(display)
|
|
|
|
self.curDisplayMediaPlayer[display] \
|
2011-06-05 21:10:49 +00:00
|
|
|
.set_visible(display, False)
|
|
|
|
|
|
|
|
def video_blank(self, msg):
|
|
|
|
"""
|
|
|
|
Blank the related video Widget
|
2011-11-24 21:10:37 +00:00
|
|
|
|
|
|
|
``msg``
|
|
|
|
First element is the boolean for Live indication
|
|
|
|
Second element is the hide mode
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
isLive = msg[1]
|
2011-10-24 20:04:29 +00:00
|
|
|
hide_mode = msg[2]
|
2011-06-05 21:10:49 +00:00
|
|
|
if isLive:
|
2011-10-26 20:11:15 +00:00
|
|
|
Receiver.send_message(u'live_display_hide', hide_mode)
|
2011-06-05 21:10:49 +00:00
|
|
|
controller = self.parent.liveController
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-11-11 16:45:25 +00:00
|
|
|
if self.curDisplayMediaPlayer[display] \
|
2011-06-05 21:10:49 +00:00
|
|
|
.state == MediaState.Playing:
|
2011-11-11 16:45:25 +00:00
|
|
|
self.curDisplayMediaPlayer[display].pause(display)
|
|
|
|
self.curDisplayMediaPlayer[display] \
|
2011-06-05 21:10:49 +00:00
|
|
|
.set_visible(display, False)
|
|
|
|
|
|
|
|
def video_unblank(self, msg):
|
|
|
|
"""
|
|
|
|
Unblank the related video Widget
|
2011-11-24 21:10:37 +00:00
|
|
|
|
|
|
|
``msg``
|
|
|
|
First element is not relevant in this context
|
|
|
|
Second element is the boolean for Live indication
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2011-10-26 20:11:15 +00:00
|
|
|
Receiver.send_message(u'live_display_show')
|
2011-06-05 21:10:49 +00:00
|
|
|
isLive = msg[1]
|
|
|
|
if isLive:
|
|
|
|
controller = self.parent.liveController
|
2011-11-11 16:45:25 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2011-06-06 19:12:14 +00:00
|
|
|
if display.controller == controller:
|
2011-11-11 16:45:25 +00:00
|
|
|
if self.curDisplayMediaPlayer[display] \
|
2011-06-05 21:10:49 +00:00
|
|
|
.state == MediaState.Paused:
|
2011-11-11 16:45:25 +00:00
|
|
|
if self.curDisplayMediaPlayer[display].play(display):
|
|
|
|
self.curDisplayMediaPlayer[display] \
|
2011-08-29 19:55:58 +00:00
|
|
|
.set_visible(display, True)
|
2011-09-28 20:54:43 +00:00
|
|
|
# Start Timer for ui updates
|
|
|
|
if not self.timer.isActive():
|
|
|
|
self.timer.start()
|
|
|
|
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
def get_audio_extensions_list(self):
|
|
|
|
audio_list = []
|
2011-11-11 16:45:25 +00:00
|
|
|
for player in self.mediaPlayers.values():
|
2011-11-24 21:10:37 +00:00
|
|
|
if player.isActive:
|
|
|
|
for item in player.audio_extensions_list:
|
|
|
|
if not item in audio_list:
|
|
|
|
audio_list.append(item)
|
2011-06-05 21:10:49 +00:00
|
|
|
return audio_list
|
|
|
|
|
|
|
|
def get_video_extensions_list(self):
|
|
|
|
video_list = []
|
2011-11-11 16:45:25 +00:00
|
|
|
for player in self.mediaPlayers.values():
|
2011-11-24 21:10:37 +00:00
|
|
|
if player.isActive:
|
|
|
|
for item in player.video_extensions_list:
|
|
|
|
if not item in video_list:
|
|
|
|
video_list.append(item)
|
2011-06-05 21:10:49 +00:00
|
|
|
return video_list
|
2011-07-20 21:16:36 +00:00
|
|
|
|
2011-11-11 16:45:25 +00:00
|
|
|
def override_player(self, override_player):
|
|
|
|
playerSettings = str(QtCore.QSettings().value(u'media/players',
|
2011-11-02 20:27:53 +00:00
|
|
|
QtCore.QVariant(u'webkit')).toString())
|
2011-11-11 16:45:25 +00:00
|
|
|
usedPlayers = playerSettings.split(u',')
|
|
|
|
if override_player in usedPlayers:
|
|
|
|
self.overridenPlayer = override_player
|
2011-09-22 18:22:35 +00:00
|
|
|
else:
|
2011-11-11 16:45:25 +00:00
|
|
|
self.overridenPlayer = ''
|
2011-09-22 18:22:35 +00:00
|
|
|
|
2011-07-20 21:16:36 +00:00
|
|
|
def finalise(self):
|
2011-09-22 18:22:35 +00:00
|
|
|
self.timer.stop()
|
2011-07-20 21:16:36 +00:00
|
|
|
for controller in self.controller:
|
|
|
|
self.video_reset(controller)
|