From 540c717dbb3e099a3cdf014375093674d9728c5e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 29 Aug 2011 22:39:15 +0200 Subject: [PATCH] Started work on an audio player with a playlist. --- openlp/core/ui/maindisplay.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 77f2e2f7c..c84e2c739 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -62,6 +62,7 @@ class MainDisplay(QtGui.QGraphicsView): self.override = {} self.retranslateUi() self.mediaObject = None + self.audioPlayer = None self.firstTime = True self.setStyleSheet(u'border: 0px; margin: 0px; padding: 0px;') self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | @@ -101,6 +102,7 @@ class MainDisplay(QtGui.QGraphicsView): if self.isLive: if not self.firstTime: self.createMediaObject() + self.createAudioPlayer() log.debug(u'Setup webView') self.webView = QtWebKit.QWebView(self) self.webView.setGeometry(0, 0, @@ -176,6 +178,12 @@ class MainDisplay(QtGui.QGraphicsView): self.videoTick) log.debug(u'Creating Phonon objects - Finished for %s', self.isLive) + def createAudioPlayer(self): + self.firstTime = False + log.debug(u'Creating audio player - Start for %s', self.isLive) + self.audioPlayer = AudioPlayer(self) + log.debug(u'Creating Phonon objects - Finished for %s', self.isLive) + def text(self, slide): """ Add the slide text from slideController @@ -587,7 +595,9 @@ class AudioPlayer(QtCore.QObject): """ log.debug(u'AudioPlayer Initialisation started') QtCore.QObject.__init__(self, parent) + self.currentIndex = 0 self.message = None + self.playlist = [] self.mediaObject = Phonon.MediaObject() self.audioObject = Phonon.AudioOutput(Phonon.VideoCategory) Phonon.createPath(self.mediaObject, self.audioObject) @@ -597,6 +607,12 @@ class AudioPlayer(QtCore.QObject): Sets up the Audio Player for use """ log.debug(u'AudioPlayer Setup') + QtCore.QObject.connect(self.mediaObject, QtCore.SIGNAL(u'finished()'), + self.onFinished) + QtCore.QObject.connect(self.mediaObject, + QtCore.SIGNAL(u'tick(qint64)'), self.onTick) + QtCore.QObject.connect(self.mediaObject, + QtCore.SIGNAL(u'aboutToFinish()'), self.onAboutToFinish()) def close(self): """ @@ -606,6 +622,23 @@ class AudioPlayer(QtCore.QObject): for path in self.mediaObject.outputPaths(): path.disconnect() + def addToPlaylist(self, filename): + self.playlist.append(Phonon.MediaSource(filename)) + + def onFinished(self): + """ + Slot to capture when the currently playing media is finished. + """ + + def onAboutToFinish(self): + """ + Just before the audio player finishes the current track, queue the next + item in the playlist, if there is one. + """ + self.currentIndex += 1 + if len(self.playlist) > self.currentIndex: + self.mediaObject.enqueue(self.playlist[self.currentIndex]) + def onMediaQueue(self, message): """ Set up a video to play from the serviceitem.