Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Play several sounds in the same time.



  • Hello,
    I am currently developping a QML application, and in a plugin I would like to play a sound (wave file).
    But there are several instances and only one sound can be played at a time. I am using Qsound to do this.

    @ QString lstmp=getenv("PROJECT");lstmp+="\recorder4.wav";
    if(!QSound::isAvailable()) qWarning("QMLCanvas error :QSound not available on this plateform");
    QSound::play(lstmp);@

    I did it with Phonon. But I tried to overload the system, ans send it every 100ms so I have the following error comming:
    QThread::start: Failed to create thread (Code d?acc?s non valide.)

    How can I test the availability of the system?


  • Moderators

    can you try the following please (instead using the the static method):
    @
    QSound first("first.wav");
    first.play();
    QSound second("second.wav");
    second.play();
    @



  • Hi again,
    using Phonon, I face a delemma:

    either I pu a local instance in the method called every time I needa sound to be played and the instance seems dynamically allocated, and my process size increase in memorry:
    @ //-------------------------------------
    //Local Sounds
    Phonon::MediaObject *lTmpmusic =
    Phonon::createPlayer(Phonon::MusicCategory,
    Phonon::MediaSource(lstmp));
    lTmpmusic->play();@

    Or I use a member in my class, but only the first sound is played
    @if(music!=NULL)
    {
    if(music->state()==Phonon::PlayingState)
    music->stop();
    music->play();
    }@

    Is there a way to have a self destructive instance when the sound is finished playing ?
    Or how to "restart" playing the sound when only one member instance is avialable?


Log in to reply