Nominate our 2022 Qt Champions!

Phonon - Play several times

  • Hi

    After several weeks searching in Internet, I give up, I could not find any answer, so I have decided to put my question here. I hope that someone can help me ;)

    I have created an app (desktop app, not mobile) that it is able to show some videos or audios. For example, I chose the number of the songs and their Urls. So, I create for each one a mediaObject and a mediaSource. I attach my media source to my media object. (Code above)

    I have to do this in this way because I want to be able to buffer all the audio in a previous step. And I can not do this if i attach one source to one media object and enqueue the rest to the same media. (because, sometimes i need to change the song after 10 seconds for example, and the signal aboutToFinish() is not called and after reading the Qt documentation, i think that the media is only buffered after set as currentSource).

    But my problem is not here. In fact, this works pretty nice. I have several Phonon::MediaObject and I wait before I know that all of them are in a StoppedState. Also, I have one Phonon::AudioOutput, so I create the path between the first audio and put it in a play state. After 10 seconds or more if i want, I put the current song in a stop state and i create the next path, with other media object and the same audiooutput. And it works. But when i try to do a loop and start again with the first song, it does not work. It only works the last song in this second loop. I think that it is something with the paths, so I have tried a lot of possibilities but I could find any solution.

    I have created different AudioOutputs (one for each song) and then, I only can listen the first song (in all the loops).

    I have stored the paths and I tried disconnecting and reconnecting, but again, it only works the first loop (with one AudioOutpu).

    Also, I tried to create all the paths before playing, but no success.

    I have the same problem with the videos, and I do not know what else I can do.

    I will appreciate some help so much... I have been the last two weeks with the same problem. :(

    I am using the Qt 4.7.4 version in Windows XP SP3

    Please let me know if something is not clear, I will try to explain it in a better way.

    Creating each song:
    Phonon::MediaSource _mSource;
    Phonon::MediaObject _mMediaObject;

    _mSource = Phonon::MediaSource(UrlAudio);

    _mvStim->getStimulus() is the mediaobject of each song
    Phonon::AudioOutput *_mpAudioOutput;

    And then, play and stop of that mediaObject.

    I have seen that in the second loop, the song sounds but before I do a play operation. It is in a play state already. This is weird.

  • any help is welcome

  • I recently made simple media player using Phonon and Phonon is great (you can spend more time on UI and stuff if media "wrangling" is abstracted) but as it is interface for gstreamer (on Linux), I had in plan to check also gstreamer, and when I saw your question, I wanted to write something in line with this:

    "Developers that require more control over a backend than Phonon can provide are recommended to use the native API or the GStreamer API on systems for which it is available.": (actually from but parsing of this forum breaks right parenthesis).

    Although I was more than pleased with one MediaObject, MediaSource and AudioOutput, and speed of changing between songs when clicking on QListWidget, I was also curious can (or cannot) Phonon handle multiple MediaObjects and AudioOutputs.

    I made simple app with 3 AudioOutputs, 3 MediaObjects and 3 MediaSources and playing and stopping any of them and changing without any problems.

    So it seems to me that you have problem with transition from one song (media file) to other and you haven't described how you do it, using aboutToFinish() or ...? And what you do in your app when you detect end of a song and want to play another?

  • Well, I have just found one solution to my problem with audios.

    I have create my audio using createPlayer instead of create one AudioOutput and create the paths between them.

    @Phonon::MediaObject *music =

    This way, I can play the same song more than one time, so i think that my error was in the paths.

    I am testing now with the videos, and I will try to use the videoPlayer but I don't know yet if it will work.

    @Phonon::VideoPlayer *player =
    new Phonon::VideoPlayer(Phonon::VideoCategory, parentWidget);

    Also, I am having some problems with some songs, because when I try to play it I have an error state that says "Class not defined". I dont know why, I have that problem even with the example of the Qt documentation. But I will try to fix it after testing the video player.

    About my transition, I am not using aboutToFinish, I have a signal every X secons, and then I change the song or video. It is like a player who lets you heard only 30 seconds of every song.

    Imagine a list like:

    So i load all the audios and wait for them to be in a StoppedState. Then I play the first one, 10 seconds after, I stop the audio1, and play the audio2, 10 seconds, stop audio2, and play audio3, and then, after 10sec, i stop the audio3 and play the audio1 again and all the sequence as before.

    But, if i use the method of my first message, it does not work, the audio1 starts playing before i do a play operation.

    But as i said, it works with the createPlayer. I think it was a problem with the paths between audioOutput and mediaObject.

    If i found a solution for the video, I will post it here.

    Thanks for doing an application only for helping me Stemd.

  • Well, it is solved

    After large search i have the solution.

    I use createPlayer and VideoPlayer and it works pretty nice.

    And about the last problem that i reported, it is all about codecs... It worked in Windows xp but not in Windows 7, so I installed the k-lite codec and it works... but only if i try with the K-Lite codec for 32bits, if I install the 64bits version, or both, it does not work.

    @For use on 64-bit versions of Windows.

    For an optimal user experience it is highly recommended to also install one
    of the 32-bit variants from above, because most software that runs on 64-bit
    versions of Windows is still 32-bit.

    Windows Vista x64 and Windows 7 x64 use a 32-bit version of Windows Media Player
    by default. Windows Media Center and Windows Explorer are 64-bit applications.
    That is why you need both 32-bit and 64-bit codecs.@

    Do not install both. Only the 32bit version ;)

    So be carefull with this... it took me a lot of time to figure it out.

Log in to reply