add vlc support

This commit is contained in:
rimach crichter@web.de 2011-04-21 15:54:44 +02:00
parent 392b5ecb47
commit e730dc366f
5 changed files with 97 additions and 36 deletions

View File

@ -178,7 +178,14 @@ sup {
vid.src = ''; vid.src = '';
vid2.src = ''; vid2.src = '';
break; break;
} case 'length':
return vid.duration;
case 'currentTime':
return vid.currentTime;
case 'seek':
vid.currentTime = path;
break;
}
} }
function show_image(src){ function show_image(src){

View File

@ -38,6 +38,7 @@ from openlp.core.lib import Receiver
from openlp.plugins.media.lib import MediaBackends, MediaStates from openlp.plugins.media.lib import MediaBackends, MediaStates
from webkitcontroller import WebkitController from webkitcontroller import WebkitController
from phononcontroller import PhononController from phononcontroller import PhononController
from vlccontroller import VlcController
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -93,7 +94,7 @@ class MediaManager(object):
self.curDisplayMediaController = {} self.curDisplayMediaController = {}
self.displayWebkitController = WebkitController(self) self.displayWebkitController = WebkitController(self)
self.displayPhononController = PhononController(self) self.displayPhononController = PhononController(self)
#self.displayVlcController = VlcController(self) self.displayVlcController = VlcController(self)
self.Timer = QtCore.QTimer() self.Timer = QtCore.QTimer()
self.Timer.setInterval(200) self.Timer.setInterval(200)
@ -134,13 +135,12 @@ class MediaManager(object):
self.Timer.stop() self.Timer.stop()
def setDisplay(self, display): def setDisplay(self, display):
#self.setupVlcController(display) self.setupVlcController(display)
self.setupPhononController(display) self.setupPhononController(display)
self.setupWebkitController(display) self.setupWebkitController(display)
def setupWebkitController(self, display): def setupWebkitController(self, display):
#self.displayWebkitController[display] = display.webView
display.webView.raise_() display.webView.raise_()
def setupPhononController(self, display): def setupPhononController(self, display):
@ -155,22 +155,11 @@ class MediaManager(object):
display.phononWidget.raise_() display.phononWidget.raise_()
def setupVlcController(self, display): def setupVlcController(self, display):
display.vlcWidget = QtGui.QWidget(display) display.vlcWidget = QtGui.QFrame(display)
instance=vlc.Instance() # creating a basic vlc instance
self.movieName = None display.vlcInstance = vlc.Instance()
player=instance.media_player_new(self.movieName) # creating an empty vlc media player
# the media player has to be 'connected' to the QFrame display.vlcMediaPlayer = display.vlcInstance.media_player_new()
# (otherwise a video would be displayed in it's own window)
# this is platform specific!
# you have to give the id of the QFrame (or similar object) to
# vlc, different platforms have different functions for this
if sys.platform == "linux2": # for Linux using the X Server
player.set_xwindow(self.hwnd)
elif sys.platform == "win32": # for Windows
player.set_hwnd(self.hwnd)
elif sys.platform == "darwin": # for MacOS
player.set_agl(self.hwnd)
display.vlcWidget.setGeometry(QtCore.QRect(0, 0, display.vlcWidget.setGeometry(QtCore.QRect(0, 0,
display.screen[u'size'].width(), display.screen[u'size'].height())) display.screen[u'size'].width(), display.screen[u'size'].height()))
display.vlcWidget.raise_() display.vlcWidget.raise_()
@ -203,14 +192,29 @@ class MediaManager(object):
""" """
usePhonon = QtCore.QSettings().value( usePhonon = QtCore.QSettings().value(
u'media/use phonon', QtCore.QVariant(True)).toBool() u'media/use phonon', QtCore.QVariant(True)).toBool()
if usePhonon and not isBackground: useVlc = True
if videoPath.endswith(u'.swf'):
useVlc = False
usePhonon = False
elif videoPath.endswith(u'.wmv'):
useVlc = False
usePhonon = True
if useVlc:
self.curDisplayMediaController[display] = self.displayVlcController
display.phononWidget.setVisible(False)
display.webView.setVisible(False)
display.vlcWidget.setVisible(True)
elif usePhonon and not isBackground:
self.curDisplayMediaController[display] = self.displayPhononController self.curDisplayMediaController[display] = self.displayPhononController
display.phononWidget.setVisible(True) display.phononWidget.setVisible(True)
display.webView.setVisible(False) display.webView.setVisible(False)
display.vlcWidget.setVisible(False)
else: else:
self.curDisplayMediaController[display] = self.displayWebkitController self.curDisplayMediaController[display] = self.displayWebkitController
display.phononWidget.setVisible(False) display.phononWidget.setVisible(False)
display.webView.setVisible(True) display.webView.setVisible(True)
display.vlcWidget.setVisible(False)
if len(self.curDisplayMediaController) > 0: if len(self.curDisplayMediaController) > 0:
if not self.Timer.isActive(): if not self.Timer.isActive():
self.Timer.start() self.Timer.start()

View File

@ -39,6 +39,7 @@ class PhononController(MediaController):
MediaController.__init__(self, parent) MediaController.__init__(self, parent)
def load(self, display, path, volume): def load(self, display, path, volume):
print "load vid in Phonon Controller"
display.phononActive = True display.phononActive = True
display.mediaObject.stop() display.mediaObject.stop()
display.mediaObject.clearQueue() display.mediaObject.clearQueue()

View File

@ -25,33 +25,70 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
from openlp.plugins.media.lib import MediaController import sys
from openlp.plugins.media.lib import MediaController, MediaStates
class VlcController(MediaController): class VlcController(MediaController):
""" """
Specialiced MediaController class Specialiced MediaController class
to reflect Features of the Vlc backend to reflect Features of the Vlc backend
""" """
def __init__(self): def __init__(self, parent):
pass self.parent = parent
MediaController.__init__(self, parent)
def load(self, display, path, volume): def load(self, display, path, volume):
pass print "load vid in Vlc Controller"
vol = float(volume) / float(10)
# create the media
display.vlcMedia = display.vlcInstance.media_new(unicode(path))
# put the media in the media player
display.vlcMediaPlayer.set_media(display.vlcMedia)
# parse the metadata of the file
display.vlcMedia.parse()
# the media player has to be 'connected' to the QFrame
# (otherwise a video would be displayed in it's own window)
# this is platform specific!
# you have to give the id of the QFrame (or similar object) to
# vlc, different platforms have different functions for this
if sys.platform == "linux2": # for Linux using the X Server
display.vlcMediaPlayer.set_xwindow(int(display.vlcWidget.winId()))
elif sys.platform == "win32": # for Windows
display.vlcMediaPlayer.set_hwnd(int(display.vlcWidget.winId()))
elif sys.platform == "darwin": # for MacOS
display.vlcMediaPlayer.set_agl(int(display.vlcWidget.winId()))
# start playing
self.play(display)
self.state = MediaStates.PlayingState
def play(self, display): def play(self, display):
self.display[u'live'] display.vlcMediaPlayer.play()
self.state = MediaStates.PlayingState
def pause(self): def pause(self, display):
pass display.vlcMediaPlayer.pause()
self.state = MediaStates.PausedState
def stop(self): def stop(self, display):
pass display.vlcMediaPlayer.stop()
self.state = MediaStates.StoppedState
def seek(self, display, seekVal): def seek(self, display, seekVal):
if display.vlcMediaPlayer.is_seekable():
display.vlcMediaPlayer.set_position(seekVal/1000.0)
def reset(self, display):
pass pass
def updateUI(self): def updateUI(self, display):
pass display.parent.seekSlider.setMaximum(1000)
if not display.parent.seekSlider.isSliderDown():
currentPos = display.vlcMediaPlayer.get_position() * 1000
display.parent.seekSlider.setSliderPosition(currentPos)
def getSupportedFileTypes(self): def getSupportedFileTypes(self):
pass pass

View File

@ -25,7 +25,7 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
from openlp.plugins.media.lib import MediaController from openlp.plugins.media.lib import MediaController, MediaStates
class WebkitController(MediaController): class WebkitController(MediaController):
""" """
@ -38,9 +38,11 @@ class WebkitController(MediaController):
self.isFlash = False self.isFlash = False
def load(self, display, path, volume): def load(self, display, path, volume):
print "load vid in Webkit Controller"
vol = float(volume) / float(10) vol = float(volume) / float(10)
display.webView.setVisible(True) display.webView.setVisible(True)
display.phononWidget.setVisible(False) display.phononWidget.setVisible(False)
display.vlcWidget.setVisible(False)
if path.endswith(u'.swf'): if path.endswith(u'.swf'):
js = u'show_flash("load","%s");' % \ js = u'show_flash("load","%s");' % \
(path.replace(u'\\', u'\\\\')) (path.replace(u'\\', u'\\\\'))
@ -50,34 +52,44 @@ class WebkitController(MediaController):
(path.replace(u'\\', u'\\\\'), str(vol)) (path.replace(u'\\', u'\\\\'), str(vol))
self.isFlash = False self.isFlash = False
display.frame.evaluateJavaScript(js) display.frame.evaluateJavaScript(js)
self.state = MediaStates.PlayingState
def play(self, display): def play(self, display):
if self.isFlash: if self.isFlash:
display.frame.evaluateJavaScript(u'show_flash("play","");') display.frame.evaluateJavaScript(u'show_flash("play","");')
else: else:
display.frame.evaluateJavaScript(u'show_video("play");') display.frame.evaluateJavaScript(u'show_video("play");')
self.state = MediaStates.PlayingState
def pause(self, display): def pause(self, display):
if self.isFlash: if self.isFlash:
display.frame.evaluateJavaScript(u'show_flash("pause","");') display.frame.evaluateJavaScript(u'show_flash("pause","");')
else: else:
display.frame.evaluateJavaScript(u'show_video("pause");') display.frame.evaluateJavaScript(u'show_video("pause");')
self.state = MediaStates.PausedState
def stop(self, display): def stop(self, display):
if self.isFlash: if self.isFlash:
display.frame.evaluateJavaScript(u'show_flash("stop","");') display.frame.evaluateJavaScript(u'show_flash("stop","");')
else: else:
display.frame.evaluateJavaScript(u'show_video("stop");') display.frame.evaluateJavaScript(u'show_video("stop");')
self.state = MediaStates.StoppedState
def seek(self, display, seekVal): def seek(self, display, seekVal):
pass if not self.isFlash:
print seekVal, float(seekVal)/1000
display.frame.evaluateJavaScript(u'show_video("seek", "%f");' % (float(seekVal)/1000))
def reset(self, display): def reset(self, display):
display.frame.evaluateJavaScript(u'show_video("close");') display.frame.evaluateJavaScript(u'show_video("close");')
def updateUI(self, display): def updateUI(self, display):
pass if not self.isFlash:
length = display.frame.evaluateJavaScript(u'show_video("length");')
display.parent.seekSlider.setMaximum(length.toFloat()[0]*1000)
if not display.parent.seekSlider.isSliderDown():
currentTime = display.frame.evaluateJavaScript(u'show_video("currentTime");')
display.parent.seekSlider.setSliderPosition(currentTime.toFloat()[0]*1000)
def getSupportedFileTypes(self): def getSupportedFileTypes(self):
pass pass