2011-04-18 19:50:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- 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 #
|
|
|
|
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
|
|
|
|
# Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, Armin Köhler, #
|
|
|
|
# Andreas Preikschat, Mattias Põldaru, Christian Richter, Philip Ridout, #
|
|
|
|
# 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 #
|
|
|
|
###############################################################################
|
|
|
|
|
2011-05-21 08:18:52 +00:00
|
|
|
import logging
|
|
|
|
|
2011-05-17 19:50:00 +00:00
|
|
|
from PyQt4 import QtCore, QtGui, QtWebKit
|
2011-05-10 20:39:17 +00:00
|
|
|
from openlp.plugins.media.lib import MediaController, MediaState
|
2011-04-18 19:50:12 +00:00
|
|
|
|
2011-05-21 08:18:52 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2011-04-18 19:50:12 +00:00
|
|
|
class WebkitController(MediaController):
|
|
|
|
"""
|
2011-04-19 12:03:36 +00:00
|
|
|
Specialiced MediaController class
|
|
|
|
to reflect Features of the QtWebkit backend
|
2011-04-18 19:50:12 +00:00
|
|
|
"""
|
2011-05-10 20:39:17 +00:00
|
|
|
|
2011-04-18 19:50:12 +00:00
|
|
|
def __init__(self, parent):
|
|
|
|
MediaController.__init__(self, parent)
|
2011-05-10 20:39:17 +00:00
|
|
|
self.parent = parent
|
2011-04-18 19:50:12 +00:00
|
|
|
self.isFlash = False
|
2011-05-23 19:37:44 +00:00
|
|
|
self.canBackground = True
|
|
|
|
self.video_extensions_list = [
|
|
|
|
u'*.3gp'
|
|
|
|
, u'*.3gpp'
|
|
|
|
, u'*.3g2'
|
|
|
|
, u'*.3gpp2'
|
|
|
|
, u'*.aac'
|
|
|
|
, u'*.flv'
|
|
|
|
, u'*.f4a'
|
|
|
|
, u'*.f4b'
|
|
|
|
, u'*.f4p'
|
|
|
|
, u'*.f4v'
|
|
|
|
, u'*.mov'
|
|
|
|
, u'*.m4a'
|
|
|
|
, u'*.m4b'
|
|
|
|
, u'*.m4p'
|
|
|
|
, u'*.m4v'
|
|
|
|
, u'*.mkv'
|
|
|
|
, u'*.mp4'
|
|
|
|
, u'*.mp3'
|
|
|
|
, u'*.ogg'
|
|
|
|
, u'*.ogv'
|
|
|
|
, u'*.webm'
|
2011-05-24 20:03:57 +00:00
|
|
|
, u'*.swf', u'*.mpg', u'*.wmv', u'*.mpeg', u'*.avi'
|
2011-05-23 19:37:44 +00:00
|
|
|
]
|
2011-04-18 19:50:12 +00:00
|
|
|
|
2011-05-23 19:37:44 +00:00
|
|
|
def setup(self, display, hasAudio):
|
2011-05-17 19:50:00 +00:00
|
|
|
display.webView.raise_()
|
|
|
|
self.hasOwnWidget = False
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_available():
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_supported_file_types(self):
|
2011-05-23 19:37:44 +00:00
|
|
|
pass
|
2011-05-17 19:50:00 +00:00
|
|
|
|
2011-05-24 20:03:57 +00:00
|
|
|
def load(self, display, path, volume, isBackground):
|
2011-05-21 08:18:52 +00:00
|
|
|
log.debug(u'load vid in Webkit Controller')
|
2011-04-18 19:50:12 +00:00
|
|
|
vol = float(volume) / float(10)
|
2011-05-24 20:03:57 +00:00
|
|
|
if isBackground:
|
|
|
|
loop = u'true'
|
|
|
|
else:
|
|
|
|
loop = u'false'
|
2011-04-18 19:50:12 +00:00
|
|
|
display.webView.setVisible(True)
|
|
|
|
if path.endswith(u'.swf'):
|
|
|
|
js = u'show_flash("load","%s");' % \
|
|
|
|
(path.replace(u'\\', u'\\\\'))
|
|
|
|
self.isFlash = True
|
|
|
|
else:
|
2011-05-24 20:03:57 +00:00
|
|
|
js = u'show_video("init", "%s", %s, %s);' % \
|
|
|
|
(path.replace(u'\\', u'\\\\'), str(vol), loop)
|
2011-04-18 19:50:12 +00:00
|
|
|
self.isFlash = False
|
|
|
|
display.frame.evaluateJavaScript(js)
|
2011-05-21 08:18:52 +00:00
|
|
|
return True
|
2011-05-10 20:39:17 +00:00
|
|
|
|
|
|
|
def resize(self, display, controller):
|
|
|
|
if display == controller.previewDisplay:
|
|
|
|
display.webView.resize(display.size())
|
2011-04-18 19:50:12 +00:00
|
|
|
|
|
|
|
def play(self, display):
|
2011-05-24 20:03:57 +00:00
|
|
|
display.override[u'theme'] = u''
|
|
|
|
display.override[u'video'] = True
|
|
|
|
display.webLoaded = True
|
2011-05-17 19:50:00 +00:00
|
|
|
self.set_visible(display, True)
|
2011-04-18 19:50:12 +00:00
|
|
|
if self.isFlash:
|
|
|
|
display.frame.evaluateJavaScript(u'show_flash("play","");')
|
|
|
|
else:
|
|
|
|
display.frame.evaluateJavaScript(u'show_video("play");')
|
2011-05-10 20:39:17 +00:00
|
|
|
self.state = MediaState.Playing
|
2011-04-18 19:50:12 +00:00
|
|
|
|
|
|
|
def pause(self, display):
|
|
|
|
if self.isFlash:
|
|
|
|
display.frame.evaluateJavaScript(u'show_flash("pause","");')
|
|
|
|
else:
|
|
|
|
display.frame.evaluateJavaScript(u'show_video("pause");')
|
2011-05-10 20:39:17 +00:00
|
|
|
self.state = MediaState.Paused
|
2011-04-18 19:50:12 +00:00
|
|
|
|
|
|
|
def stop(self, display):
|
|
|
|
if self.isFlash:
|
|
|
|
display.frame.evaluateJavaScript(u'show_flash("stop","");')
|
|
|
|
else:
|
|
|
|
display.frame.evaluateJavaScript(u'show_video("stop");')
|
2011-05-10 20:39:17 +00:00
|
|
|
self.state = MediaState.Stopped
|
|
|
|
|
|
|
|
def volume(self, display, vol):
|
|
|
|
if not self.isFlash:
|
|
|
|
display.frame.evaluateJavaScript(u'show_video(null, null, %s);' %
|
|
|
|
str(vol))
|
2011-04-18 19:50:12 +00:00
|
|
|
|
2011-04-19 12:03:36 +00:00
|
|
|
def seek(self, display, seekVal):
|
2011-04-21 13:54:44 +00:00
|
|
|
if not self.isFlash:
|
2011-05-17 19:50:00 +00:00
|
|
|
seek = float(seekVal)/1000
|
2011-05-21 08:18:52 +00:00
|
|
|
display.frame.evaluateJavaScript( \
|
|
|
|
u'show_video("seek", null, null, null, "%f");' % (seek))
|
2011-04-18 19:50:12 +00:00
|
|
|
|
|
|
|
def reset(self, display):
|
2011-05-10 20:39:17 +00:00
|
|
|
if self.isFlash:
|
|
|
|
display.frame.evaluateJavaScript(u'show_flash("close","");')
|
|
|
|
else:
|
|
|
|
display.frame.evaluateJavaScript(u'show_video("close");')
|
2011-05-17 19:50:00 +00:00
|
|
|
self.state = MediaState.Off
|
|
|
|
|
|
|
|
def set_visible(self, display, status):
|
|
|
|
if self.hasOwnWidget:
|
|
|
|
display.webView.setVisible(status)
|
2011-04-19 12:03:36 +00:00
|
|
|
|
2011-05-10 20:39:17 +00:00
|
|
|
def update_ui(self, controller, display):
|
2011-04-21 13:54:44 +00:00
|
|
|
if not self.isFlash:
|
2011-05-21 08:18:52 +00:00
|
|
|
currentTime = display.frame.evaluateJavaScript( \
|
|
|
|
u'show_video("currentTime");')
|
2011-04-21 13:54:44 +00:00
|
|
|
length = display.frame.evaluateJavaScript(u'show_video("length");')
|
2011-05-17 19:50:00 +00:00
|
|
|
if int(currentTime.toFloat()[0]*1000) > 0:
|
|
|
|
controller.seekSlider.setMaximum(int(length.toFloat()[0]*1000))
|
|
|
|
if not controller.seekSlider.isSliderDown():
|
2011-05-21 08:18:52 +00:00
|
|
|
controller.seekSlider.setSliderPosition( \
|
|
|
|
int(currentTime.toFloat()[0]*1000))
|
2011-04-19 12:03:36 +00:00
|
|
|
|
2011-05-10 20:39:17 +00:00
|
|
|
def get_supported_file_types(self):
|
2011-04-19 12:03:36 +00:00
|
|
|
pass
|