Phonon and queue



  • I'm trying to use phonon as sound backend; really I didn't understand how it works!
    My code, just erasing the obviously code, is this:
    @
    function play(QSound file)
    {
    this->media->enqueue(sound);
    this->media->play();
    }
    @
    @
    play("test.wav")
    play("trial.wav")
    @

    So if I put 2 sound clips it works; after hearing those, if I put other two ones, nothing happen, no error and no sounds!

    Is there someone that know how i can do?



  • Ok, i've better read documentation...is not so clear, but I've got an intuition...so I've tried and now it's work!

    So, when I put several clips and then I start playing, it works as aspected: play sounds one after other one until queue is not empty; when it ends with all sounds, calling the same code doesn't work as espected because the queue is elaborated only if the media is currently playing.
    So the solution is this:
    @
    void RadioVoicePhononControl::play(QString sound)
    {
    if (this->media->state() == Phonon::PlayingState || this->media->state() == Phonon::LoadingState)
    this->media->enqueue(sound);
    else
    this->media->setCurrentSource(sound);
    }

    void RadioVoicePhononControl::stateChanged(Phonon::State newstate, Phonon::State)
    {
    if (newstate == Phonon::StoppedState) // this state will be set when media has loaded clip
    this->media->play();
    }
    @

    That works because of setCurrentSource(...) that reactivates playing and eventually use the queue.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.