Optional phonon videos, start

This commit is contained in:
Jonathan Corwin 2010-10-01 23:47:37 +01:00
parent 4b5541e97b
commit f331f13278
3 changed files with 50 additions and 14 deletions

View File

@ -114,6 +114,8 @@ class MainDisplay(DisplayWidget):
"""
log.debug(u'Setup live = %s for %s ' % (self.isLive,
self.screens.monitor_number))
self.usePhonon = QtCore.QSettings().value(
u'media/use phonon', QtCore.QVariant(False)).toBool()
self.screen = self.screens.current
self.setVisible(False)
self.setGeometry(self.screen[u'size'])
@ -139,6 +141,14 @@ class MainDisplay(DisplayWidget):
QtCore.Qt.ScrollBarAlwaysOff)
self.frame.setScrollBarPolicy(QtCore.Qt.Horizontal,
QtCore.Qt.ScrollBarAlwaysOff)
self.videowidget = Phonon.VideoWidget(self)
self.videowidget.setVisible(False)
self.videowidget.setGeometry(QtCore.QRect(0, 0,
self.screen[u'size'].width(), self.screen[u'size'].height()))
self.mediaObject = Phonon.MediaObject(self)
self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self.mediaObject)
Phonon.createPath(self.mediaObject, self.videowidget)
Phonon.createPath(self.mediaObject, self.audio)
if self.isLive:
# Build the initial frame.
self.black = QtGui.QImage(
@ -259,13 +269,20 @@ class MainDisplay(DisplayWidget):
Used after Video plugin has changed the background
"""
log.debug(u'resetVideo')
if isBackground or not self.usePhonon:
self.frame.evaluateJavaScript(u'show_video("close");')
else:
self.mediaObject.stop()
self.mediaObject.clearQueue()
def videoPlay(self):
"""
Responds to the request to play a loaded video
"""
log.debug(u'videoPlay')
if self.usePhonon:
self.mediaObject.play()
else:
self.frame.evaluateJavaScript(u'show_video("play");')
# show screen
if self.isLive:
@ -276,6 +293,9 @@ class MainDisplay(DisplayWidget):
Responds to the request to pause a loaded video
"""
log.debug(u'videoPause')
if self.usePhonon:
self.mediaObject.pause()
else:
self.frame.evaluateJavaScript(u'show_video("pause");')
def videoStop(self):
@ -283,6 +303,11 @@ class MainDisplay(DisplayWidget):
Responds to the request to stop a loaded video
"""
log.debug(u'videoStop')
if self.usePhonon:
self.mediaObject.stop()
self.webView.setVisible(True)
self.videowidget.setVisible(False)
else:
self.frame.evaluateJavaScript(u'show_video("stop");')
def videoVolume(self, volume):
@ -290,18 +315,30 @@ class MainDisplay(DisplayWidget):
Changes the volume of a running video
"""
log.debug(u'videoVolume %d' % volume)
if self.usePhonon:
self.audio.setVolume(volume)
else:
self.frame.evaluateJavaScript(u'show_video(null, null, %s);' %
str(float(volume)/float(10)))
def video(self, videoPath, volume):
def video(self, videoPath, volume, isBackground=False):
"""
Loads and starts a video to run with the option of sound
"""
log.debug(u'video')
self.loaded = True
if isBackground or not self.usePhonon:
js = u'show_video("init", "%s", %s, true); show_video("play");' % \
(videoPath.replace(u'\\', u'\\\\'), str(float(volume)/float(10)))
(videoPath.replace(u'\\', u'\\\\'), \
str(float(volume)/float(10)))
self.frame.evaluateJavaScript(js)
else:
self.mediaObject.stop()
self.mediaObject.clearQueue()
self.mediaObject.setCurrentSource(Phonon.MediaSource(videoPath))
self.mediaObject.play()
self.webView.setVisible(False)
self.videowidget.setVisible(True)
return self.preview()
def isLoaded(self):

View File

@ -926,14 +926,13 @@ class SlideController(QtGui.QWidget):
Respond to the arrival of a media service item
"""
log.debug(u'SlideController onMediaStart')
if self.isLive:
file = os.path.join(item.get_frame_path(), item.get_frame_title())
if self.isLive:
self.display.video(file, self.volume)
self.volumeSlider.setValue(self.volume)
else:
self.mediaObject.stop()
self.mediaObject.clearQueue()
file = os.path.join(item.get_frame_path(), item.get_frame_title())
self.mediaObject.setCurrentSource(Phonon.MediaSource(file))
self.seekSlider.setMediaObject(self.mediaObject)
self.seekSlider.show()

View File

@ -115,7 +115,7 @@ class MediaMediaItem(MediaManagerItem):
'You must select a media file to replace the background with.')):
item = self.listView.currentItem()
filename = unicode(item.data(QtCore.Qt.UserRole).toString())
self.parent.liveController.display.video(filename, 0)
self.parent.liveController.display.video(filename, 0, True)
self.resetButton.setVisible(True)
def generateSlideData(self, service_item, item=None):