Take the 2-minute tour ×

With the code I have right now I CAN play .mp3 data from files succesfully. However I need to play the same data using a QtCore.QBuffer (NOT from a file). When I use the example of the docs it errors an unexpected type of QBuffer! However...... that is what it SHOULD see, according to the docs.

But............... it throws:

TypeError: Phonon.MediaObject.setCurrentSource(Phonon.MediaSource): argument 1 has unexpected type 'QBuffer'

The code I use is (1):

    someBuffer = QtCore.QBuffer()

I also tried (2):

    someBuffer = QtCore.QBuffer()

and (3):

    someBuffer = QtCore.QBuffer()

The last example (3) throws an different ERROR and wipes my Gui off screen ;-)

    ASSERT: "d->connected" in file /builddir/build/BUILD/phonon-4.5.1/phonon/streaminterface.cpp, line xxxx 

TrackData contains the mp3 data and IS PLAYING OK when I write it to a File and use that as a resource to mediaObject.setCurrentSource(Phonon.MediaSource())I also experimented with a QByteArray but that leads to the same "unexpected QBuffer" error. To be more precise everything I feed setCurrentSource is not accepted. Tried a string (errors an unexpected type of String), tried a QBuffer (errors an unexpected type of QBuffer), tried a QByteArray (errors an unexpected type of QByteArray).

BTW: I run Qt, PyQt on Linux.

Any ideas??

share|improve this question
add comment

1 Answer

From the PyQt docs, it looks like setCurrentSource expects a MediaSource object. MediaSource objects can be initialized with QIODevice objects; QBuffer is a subclass of QIODevice. Perhaps you need to wrap your QBuffer in a MediaSource:

someBuffer = QtCore.QBuffer()
sourceWrapper = Phonon.MediaSource(someBuffer)

The documentation seems to suggest that you shouldn't need to do this, that the MediaSource object should be implicitly constructed. I think they might be wrong though. I just did a quick test: calling setCurrentSource on the QBuffer raised an error like you got. However, wrapping it in a MediaSource and calling setCurrentSource on that worked fine.

share|improve this answer
I tried your sample code and even other methods but it still is not working. Did you really test that with .mp3 data? Did it play sound? –  thedax Feb 14 '13 at 11:34
I did, and I've just tested it again. It plays fine. –  Whatang Feb 18 '13 at 18:08
add comment

Your Answer


