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 #
|
2012-06-22 14:14:53 +00:00
|
|
|
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
|
|
|
# Meinert Jordan, Armin Köhler, Edwin Lunando, Joshua Miller, Stevan Pettit, #
|
|
|
|
# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, #
|
|
|
|
# Simon Scudder, Jeffrey Smith, Maikel Stuivenberg, Martin Thompson, Jon #
|
|
|
|
# Tibble, Dave Warnock, Frode Woldsund #
|
2011-06-05 21:10:49 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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
|
2012-09-15 11:16:58 +00:00
|
|
|
import sys
|
2011-12-02 21:13:05 +00:00
|
|
|
from PyQt4 import QtCore, QtGui
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
from openlp.core.lib import OpenLPToolbar, Receiver, translate
|
2012-05-11 12:22:34 +00:00
|
|
|
from openlp.core.lib.settings import Settings
|
2011-12-02 21:13:05 +00:00
|
|
|
from openlp.core.lib.ui import critical_error_message_box
|
2012-03-16 21:52:15 +00:00
|
|
|
from openlp.core.ui.media import MediaState, MediaInfo, MediaType, \
|
|
|
|
get_media_players, set_media_players
|
2012-09-09 06:06:44 +00:00
|
|
|
from openlp.core.ui.media.mediaplayer import MediaPlayer
|
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
|
2012-08-05 18:17:52 +00:00
|
|
|
class for every Player. Currently these are QtWebkit, Phonon and Vlc.
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, parent):
|
2012-10-04 17:28:49 +00:00
|
|
|
self.mainWindow = 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.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)
|
2012-10-06 08:35:37 +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(),
|
2012-03-16 21:52:15 +00:00
|
|
|
QtCore.SIGNAL(u'playbackPlay'), self.video_play)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2012-03-16 21:52:15 +00:00
|
|
|
QtCore.SIGNAL(u'playbackPause'), self.video_pause)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2012-03-16 21:52:15 +00:00
|
|
|
QtCore.SIGNAL(u'playbackStop'), self.video_stop)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2012-03-16 21:52:15 +00:00
|
|
|
QtCore.SIGNAL(u'seekSlider'), self.video_seek)
|
2011-06-05 21:10:49 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
2012-03-16 21:52:15 +00:00
|
|
|
QtCore.SIGNAL(u'volumeSlider'), 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-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(),
|
2012-10-06 08:35:37 +00:00
|
|
|
QtCore.SIGNAL(u'mediaitem_media_rebuild'), self._set_active_players)
|
2011-11-24 21:10:37 +00:00
|
|
|
|
2012-10-06 08:35:37 +00:00
|
|
|
def _set_active_players(self):
|
2012-03-16 21:52:15 +00:00
|
|
|
savedPlayers = get_media_players()[0]
|
2011-11-30 17:06:57 +00:00
|
|
|
for player in self.mediaPlayers.keys():
|
2012-04-28 11:13:16 +00:00
|
|
|
self.mediaPlayers[player].isActive = player in savedPlayers
|
2011-06-05 21:10:49 +00:00
|
|
|
|
2012-10-04 20:12:09 +00:00
|
|
|
def register_players(self, player):
|
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
|
2012-10-04 20:12:09 +00:00
|
|
|
|
|
|
|
``player``
|
|
|
|
Individual player class which has been enabled
|
2011-07-10 21:43:07 +00:00
|
|
|
"""
|
2012-10-04 20:12:09 +00:00
|
|
|
self.mediaPlayers[player.name] = player
|
2011-07-10 21:43:07 +00:00
|
|
|
|
2012-10-06 08:35:37 +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
|
|
|
"""
|
2012-10-06 08:35:37 +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):
|
2012-09-15 11:16:58 +00:00
|
|
|
# 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':
|
2012-09-15 11:29:55 +00:00
|
|
|
log.warn(u'Disabling vlc media player')
|
2012-09-15 11:16:58 +00:00
|
|
|
continue
|
2012-10-06 08:37:40 +00:00
|
|
|
if filename.endswith(u'player.py')and not\
|
|
|
|
filename == 'mediaplayer.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(), [])
|
2012-09-15 11:09:59 +00:00
|
|
|
# On some platforms importing vlc.py might cause
|
2012-09-15 11:16:58 +00:00
|
|
|
# also OSError exceptions. (e.g. Mac OS X)
|
2012-09-15 11:09:59 +00:00
|
|
|
except (ImportError, OSError):
|
2011-07-10 21:43:07 +00:00
|
|
|
log.warn(u'Failed to import %s on path %s',
|
|
|
|
modulename, path)
|
2012-10-04 20:12:09 +00:00
|
|
|
player_classes = MediaPlayer.__subclasses__()
|
|
|
|
for player_class in player_classes:
|
|
|
|
player = player_class(self)
|
|
|
|
self.register_players(player)
|
2012-04-28 11:13:16 +00:00
|
|
|
if not self.mediaPlayers:
|
2011-07-10 21:43:07 +00:00
|
|
|
return False
|
2012-04-28 11:13:16 +00:00
|
|
|
savedPlayers, overriddenPlayer = get_media_players()
|
|
|
|
invalidMediaPlayers = [mediaPlayer for mediaPlayer in savedPlayers
|
|
|
|
if not mediaPlayer in self.mediaPlayers or not
|
|
|
|
self.mediaPlayers[mediaPlayer].check_available()]
|
|
|
|
if invalidMediaPlayers:
|
|
|
|
for invalidPlayer in invalidMediaPlayers:
|
|
|
|
savedPlayers.remove(invalidPlayer)
|
|
|
|
set_media_players(savedPlayers, overriddenPlayer)
|
2012-10-06 08:35:37 +00:00
|
|
|
self._set_active_players()
|
2012-04-28 11:13:16 +00:00
|
|
|
return True
|
2011-07-10 21:43:07 +00:00
|
|
|
|
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
|
|
|
"""
|
2012-04-28 11:13:16 +00:00
|
|
|
if not self.curDisplayMediaPlayer.keys():
|
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)
|
2012-04-28 11:13:16 +00:00
|
|
|
if self.curDisplayMediaPlayer[display].state == \
|
|
|
|
MediaState.Playing:
|
2011-11-02 20:27:53 +00:00
|
|
|
return
|
2012-03-13 19:54:16 +00:00
|
|
|
# no players are active anymore
|
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2012-04-28 11:13:16 +00:00
|
|
|
if self.curDisplayMediaPlayer[display].state != MediaState.Paused:
|
2012-03-16 21:09:27 +00:00
|
|
|
display.controller.seekSlider.setSliderPosition(0)
|
2011-11-02 20:27:53 +00:00
|
|
|
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
|
|
|
|
|
2012-10-04 20:12:09 +00:00
|
|
|
def register_controller(self, controller, control_panel):
|
|
|
|
"""
|
|
|
|
Registers media controls where the players will be placed to run.
|
|
|
|
|
|
|
|
``controller``
|
|
|
|
The controller where a player will be placed
|
|
|
|
|
|
|
|
``controller_panel``
|
|
|
|
The controllers toolbar where the widgets reside
|
|
|
|
"""
|
2011-06-05 21:10:49 +00:00
|
|
|
self.controller.append(controller)
|
|
|
|
self.setup_generic_controls(controller, control_panel)
|
|
|
|
|
|
|
|
def setup_generic_controls(self, controller, control_panel):
|
2011-11-02 20:27:53 +00:00
|
|
|
"""
|
2012-10-04 20:12:09 +00:00
|
|
|
Set up controls on the control_panel for a given controller
|
|
|
|
|
|
|
|
``controller``
|
|
|
|
First element is the controller which should be used
|
|
|
|
|
|
|
|
``controller_panel``
|
|
|
|
First element is the controller which should be used
|
2011-11-02 20:27:53 +00:00
|
|
|
"""
|
2011-06-05 21:10:49 +00:00
|
|
|
controller.media_info = MediaInfo()
|
|
|
|
# Build a Media ToolBar
|
|
|
|
controller.mediabar = OpenLPToolbar(controller)
|
2012-09-06 17:12:02 +00:00
|
|
|
controller.mediabar.addToolbarAction(u'playbackPlay',
|
2012-03-02 10:22:52 +00:00
|
|
|
text=u'media_playback_play',
|
|
|
|
icon=u':/slides/media_playback_start.png',
|
|
|
|
tooltip=translate('OpenLP.SlideController', 'Start playing media.'),
|
|
|
|
triggers=controller.sendToPlugins)
|
2012-03-03 13:52:57 +00:00
|
|
|
controller.mediabar.addToolbarAction(u'playbackPause',
|
2012-03-02 10:22:52 +00:00
|
|
|
text=u'media_playback_pause',
|
|
|
|
icon=u':/slides/media_playback_pause.png',
|
|
|
|
tooltip=translate('OpenLP.SlideController', 'Pause playing media.'),
|
|
|
|
triggers=controller.sendToPlugins)
|
2012-03-03 13:52:57 +00:00
|
|
|
controller.mediabar.addToolbarAction(u'playbackStop',
|
2012-03-02 10:22:52 +00:00
|
|
|
text=u'media_playback_stop',
|
|
|
|
icon=u':/slides/media_playback_stop.png',
|
|
|
|
tooltip=translate('OpenLP.SlideController', 'Stop playing media.'),
|
|
|
|
triggers=controller.sendToPlugins)
|
2011-06-05 21:10:49 +00:00
|
|
|
# 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))
|
2012-03-02 12:11:13 +00:00
|
|
|
controller.seekSlider.setObjectName(u'seekSlider')
|
|
|
|
controller.mediabar.addToolbarWidget(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))
|
2012-03-02 12:11:13 +00:00
|
|
|
controller.volumeSlider.setObjectName(u'volumeSlider')
|
|
|
|
controller.mediabar.addToolbarWidget(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
|
|
|
|
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
|
2012-10-06 08:35:37 +00:00
|
|
|
self._set_active_players()
|
2011-06-05 21:10:49 +00:00
|
|
|
display.hasAudio = True
|
2012-10-04 17:28:49 +00:00
|
|
|
if display == self.mainWindow.previewController.previewDisplay or \
|
|
|
|
display == self.mainWindow.liveController.previewDisplay:
|
2011-06-05 21:10:49 +00:00
|
|
|
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)
|
2012-01-19 19:13:19 +00:00
|
|
|
if controller.isLive and controller.display:
|
|
|
|
if self.curDisplayMediaPlayer and value:
|
2012-03-12 19:35:29 +00:00
|
|
|
if self.curDisplayMediaPlayer[controller.display] != \
|
|
|
|
self.mediaPlayers[u'webkit']:
|
2012-01-19 19:13:19 +00:00
|
|
|
controller.display.setTransparency(False)
|
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
|
|
|
|
2012-09-14 16:35:07 +00:00
|
|
|
def video(self, controller, serviceItem, muted, isBackground,
|
|
|
|
hidden=False):
|
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()
|
2012-09-14 16:35:07 +00:00
|
|
|
controller.media_info.file_info = QtCore.QFileInfo(serviceItem.get_filename())
|
2011-07-18 21:25:10 +00:00
|
|
|
controller.media_info.is_background = isBackground
|
2011-10-24 20:04:29 +00:00
|
|
|
display = None
|
2012-10-04 17:28:49 +00:00
|
|
|
#self.curDisplayMediaPlayer[u'current'] = serviceItem.name
|
2011-06-05 21:10:49 +00:00
|
|
|
if controller.isLive:
|
2012-09-29 18:58:18 +00:00
|
|
|
if controller.previewDisplay:
|
2011-06-05 21:10:49 +00:00
|
|
|
display = controller.previewDisplay
|
2012-10-06 08:10:28 +00:00
|
|
|
isValid = self._check_file_type(controller, display)
|
2011-06-05 21:10:49 +00:00
|
|
|
display = controller.display
|
2012-10-06 08:10:28 +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:
|
2011-12-31 17:36:23 +00:00
|
|
|
controller.media_info.start_time = \
|
|
|
|
display.serviceItem.start_time
|
2012-09-14 16:35:07 +00:00
|
|
|
controller.media_info.end_time = 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
|
2012-10-06 08:10:28 +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
|
2012-04-28 11:13:16 +00:00
|
|
|
if controller.isLive and not controller.media_info.is_background:
|
2011-11-24 21:10:37 +00:00
|
|
|
display.frame.evaluateJavaScript(u'show_video( \
|
|
|
|
"setBackBoard", null, null, null,"visible");')
|
2012-09-07 16:58:13 +00:00
|
|
|
# now start playing - Preview is autoplay!
|
|
|
|
autoplay = False
|
|
|
|
# Preview requested
|
|
|
|
if not controller.isLive:
|
|
|
|
autoplay = True
|
2012-09-14 16:35:07 +00:00
|
|
|
# Visible or background requested or Service Item wants autostart
|
|
|
|
elif not hidden or controller.media_info.is_background or \
|
|
|
|
serviceItem.will_auto_start:
|
2012-09-07 16:58:13 +00:00
|
|
|
autoplay = True
|
|
|
|
# Unblank on load set
|
|
|
|
elif Settings().value(u'general/auto unblank',
|
|
|
|
QtCore.QVariant(False)).toBool():
|
|
|
|
autoplay = True
|
|
|
|
if autoplay:
|
2011-12-01 18:07:15 +00:00
|
|
|
if not self.video_play([controller]):
|
2012-09-08 18:29:05 +00:00
|
|
|
critical_error_message_box(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Unsupported File'),
|
|
|
|
unicode(translate('MediaPlugin.MediaItem',
|
2012-09-08 18:39:15 +00:00
|
|
|
'Unsupported File')))
|
2012-09-08 18:29:05 +00:00
|
|
|
return False
|
2011-12-01 18:07:15 +00:00
|
|
|
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
|
|
|
|
2012-09-14 16:35:07 +00:00
|
|
|
def media_length(self, controller, serviceItem):
|
2012-09-09 06:54:09 +00:00
|
|
|
"""
|
2012-09-14 16:35:07 +00:00
|
|
|
Loads and starts a media item to obtain the media length
|
|
|
|
|
2012-10-06 08:10:28 +00:00
|
|
|
``controller``
|
2012-09-14 16:35:07 +00:00
|
|
|
First element is the controller which should be used
|
|
|
|
|
|
|
|
``serviceItem``
|
|
|
|
The ServiceItem containing the details to be played.
|
2012-09-09 06:54:09 +00:00
|
|
|
"""
|
|
|
|
log.debug(u'media_length')
|
|
|
|
# stop running videos
|
|
|
|
self.video_reset(controller)
|
|
|
|
controller.media_info = MediaInfo()
|
|
|
|
controller.media_info.volume = controller.volumeSlider.value()
|
2012-09-14 16:35:07 +00:00
|
|
|
controller.media_info.file_info = QtCore.QFileInfo(serviceItem
|
2012-09-09 06:54:09 +00:00
|
|
|
.get_filename())
|
|
|
|
display = controller.previewDisplay
|
2012-10-06 08:10:28 +00:00
|
|
|
if not self._check_file_type(controller, display):
|
2012-09-09 06:54:09 +00:00
|
|
|
# Media could not be loaded correctly
|
|
|
|
critical_error_message_box(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Unsupported File'),
|
|
|
|
unicode(translate('MediaPlugin.MediaItem',
|
|
|
|
'Unsupported File')))
|
|
|
|
return False
|
|
|
|
if not self.video_play([controller]):
|
|
|
|
critical_error_message_box(
|
|
|
|
translate('MediaPlugin.MediaItem', 'Unsupported File'),
|
|
|
|
unicode(translate('MediaPlugin.MediaItem',
|
|
|
|
'Unsupported File')))
|
|
|
|
return False
|
2012-09-14 16:35:07 +00:00
|
|
|
serviceItem.set_media_length(controller.media_info.length)
|
2012-09-09 06:54:09 +00:00
|
|
|
self.video_stop([controller])
|
|
|
|
log.debug(u'use %s controller' % self.curDisplayMediaPlayer[display])
|
|
|
|
return True
|
|
|
|
|
2012-10-06 08:10:28 +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
|
2012-10-06 08:10:28 +00:00
|
|
|
|
|
|
|
``controller``
|
|
|
|
First element is the controller which should be used
|
|
|
|
|
|
|
|
``serviceItem``
|
|
|
|
The ServiceItem containing the details to be played.
|
2011-06-05 21:10:49 +00:00
|
|
|
"""
|
2012-03-16 21:52:15 +00:00
|
|
|
usedPlayers, overriddenPlayer = get_media_players()
|
2012-03-21 19:30:18 +00:00
|
|
|
if overriddenPlayer and overriddenPlayer != u'auto':
|
2012-03-16 21:52:15 +00:00
|
|
|
usedPlayers = [overriddenPlayer]
|
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
|
|
|
|
2012-04-28 11:13:16 +00:00
|
|
|
``msg``
|
2011-11-24 21:10:37 +00:00
|
|
|
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)
|
2012-03-13 19:54:16 +00:00
|
|
|
controller.seekSlider.setSliderPosition(0)
|
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')
|
2012-01-11 20:51:11 +00:00
|
|
|
self.set_controls_visible(controller, False)
|
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
|
|
|
|
|
|
|
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]
|
2012-04-28 11:13:16 +00:00
|
|
|
if not isLive:
|
|
|
|
return
|
2012-10-04 17:28:49 +00:00
|
|
|
controller = self.mainWindow.liveController
|
2012-04-28 11:13:16 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
2012-06-09 15:46:01 +00:00
|
|
|
if display.controller != controller or \
|
2012-04-28 11:37:39 +00:00
|
|
|
self.curDisplayMediaPlayer[display].state != MediaState.Playing:
|
2012-04-28 11:13:16 +00:00
|
|
|
continue
|
|
|
|
self.curDisplayMediaPlayer[display].pause(display)
|
|
|
|
self.curDisplayMediaPlayer[display].set_visible(display, False)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
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]
|
2012-04-28 11:13:16 +00:00
|
|
|
if not isLive:
|
|
|
|
return
|
|
|
|
Receiver.send_message(u'live_display_hide', hide_mode)
|
2012-10-04 17:28:49 +00:00
|
|
|
controller = self.mainWindow.liveController
|
2012-04-28 11:13:16 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
|
|
|
if display.controller != controller or \
|
|
|
|
self.curDisplayMediaPlayer[display].state != MediaState.Playing:
|
|
|
|
continue
|
|
|
|
self.curDisplayMediaPlayer[display].pause(display)
|
|
|
|
self.curDisplayMediaPlayer[display].set_visible(display, False)
|
2011-06-05 21:10:49 +00:00
|
|
|
|
|
|
|
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]
|
2012-04-28 11:13:16 +00:00
|
|
|
if not isLive:
|
|
|
|
return
|
2012-10-04 17:28:49 +00:00
|
|
|
controller = self.mainWindow.liveController
|
2012-04-28 11:13:16 +00:00
|
|
|
for display in self.curDisplayMediaPlayer.keys():
|
|
|
|
if display.controller != controller or \
|
|
|
|
self.curDisplayMediaPlayer[display].state != MediaState.Paused:
|
|
|
|
continue
|
|
|
|
if self.curDisplayMediaPlayer[display].play(display):
|
|
|
|
self.curDisplayMediaPlayer[display].set_visible(display, True)
|
|
|
|
# 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:
|
2012-04-28 11:13:16 +00:00
|
|
|
video_list.extend([item for item in player.video_extensions_list
|
|
|
|
if item not in video_list])
|
2011-06-05 21:10:49 +00:00
|
|
|
return video_list
|
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)
|