[PyQt] multiple sound files in queue in phonon

Haarman haarman at gmail.com
Sat Jan 2 21:57:51 GMT 2010


Hi,

I am trying to figure out how I can add wav files to phonon so it will
just play them all in the order added. Somehow phonon just plays one
file and then just a very small part of another. Anyone knows what I
am doing wrong here?

# -*- coding: utf-8 -*-

import sys, time

from PyQt4.QtGui import QApplication, QMainWindow
from PyQt4.QtGui import QFrame
from PyQt4.QtCore import SIGNAL, QObject
from PyQt4.phonon import Phonon

class MainWindow(QMainWindow):


    def __init__(self):
        QMainWindow.__init__(self)
        self.sounds = [
            #' /usr/share/kde4/apps/korganizer/sounds/onscreen.wav',
            #' /usr/share/kde4/apps/korganizer/sounds/onscreen.wav',
            #' /usr/share/kde4/apps/korganizer/sounds/onscreen.wav',
            '/usr/share/psi/sound/ft_complete.wav',
            '/usr/share/psi/sound/online.wav',
            '/usr/share/psi/sound/ft_incoming.wav',
            ]

        self.m_media = Phonon.MediaObject(self)
        audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
        Phonon.createPath(self.m_media, audioOutput)

        QObject.connect(self.m_media, SIGNAL('aboutToFinish()'),
self.enqueueNextSource)
        QObject.connect(self.m_media,
SIGNAL('stateChanged(Phonon::State, Phonon::State)'),
self.stateChanged)

        self.m_media.setCurrentSource(Phonon.MediaSource(Phonon.MediaSource(self.sounds.pop())))

        self.m_media.play()


    def stateChanged(self, newState, oldState):
         print 'stateChanged from %s to %s' % (oldState, newState)
         if oldState == Phonon.LoadingState and newState == Phonon.StoppedState:
             print 'play'
             self.m_media.play()
             pass

         if newState == Phonon.ErrorState:
             print self.m_media.errorType()


    def enqueueNextSource(self):
        print self.m_media.currentSource

        if len(self.sounds) > 0:
            self.m_media.enqueue(Phonon.MediaSource(Phonon.MediaSource(self.sounds.pop())))


def main():
    app = QApplication(sys.argv)
    QApplication.setApplicationName("Phonon test")
    mw = MainWindow()
    mw.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

thx!


More information about the PyQt mailing list