Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. QSoundEffect for WebAssembly
Forum Updated to NodeBB v4.3 + New Features

QSoundEffect for WebAssembly

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
6 Posts 2 Posters 815 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PeterT
    wrote on last edited by PeterT
    #1

    Hi folks,

    There is an officially announced support of Qt Multimedia for WebAssembly since release 6.2, but unfortunately I couldn't make it work.
    I am trying to use QSoundEffect in a simple WebAssembly app with no success. What I tried is to play a wav audio from a resource file. I have installed Qt for WebAssembly 6.2.2 and 6.3.0. The app compiles and run successfully, but no any sound is produced. The same code compiles and run on Windows (MinGW 64bit), and the sound is ok.
    In my *.pro file is added: QT += multimedia

    I have a resource file with a single resource:

    <RCC>
    <qresource prefix="/">
    <file>door-bell.wav</file>
    </qresource>
    </RCC>

    (the above assumes the resource is put directly in the project folder, but I have tried in a subfolder as well, which works fine on Windows)

    In my app class header (It is QDialog):
    #include <QSoundEffect>
    And I have a member object:
    QSoundEffect soundDoorBell;

    In my app class constructor I have tried to set the audio source in two ways, both work on Windows:
    this->soundDoorBell.setSource(QUrl("qrc:/door-bell.wav")); // Works on Win
    this->soundDoorBell.setSource(QUrl::fromLocalFile(":/door-bell.wav")); // Works on Win

    this->soundDoorBell.setLoopCount(1);
    this->soundDoorBell.setVolume(1.0);

    Then the play method is called either from a timer, or a push button click slot:

    this->soundDoorBell.play();

    This work successfully on windows, but not when my webassembly app is deployed. I have tried on both Chrome (Version 102.0.5005.63), and Edge (Version 101.0.1210.53).

    During my experiments, on the same app, a resource image was successfully used as a stylesheet, and this worked well for both Windows target and WebAssembly, see the example below:
    LabelLogo->setStyleSheet("image: url(:/Logo.png;");

    I could not find much info or examples for Qt Multimedia for WebAssembly, except this forum thread:

    https://forum.qt.io/topic/122313/webassembly-and-sound-effects/17

    and the bug report regarding the module support, where the bug status is stated "Resolved" since 23 Aug 2021:

    https://bugreports.qt.io/browse/QTBUG-69444

    Please advise me on the proper use of a local resource as a QSoundEffect source if I do something wrong!

    Thanks,
    Peter

    1 Reply Last reply
    0
    • lorn.potterL Offline
      lorn.potterL Offline
      lorn.potter
      wrote on last edited by lorn.potter
      #2

      QAudioSink should work in Qt webassembly, so QSoundEffect should work. I will look into this.

      Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
      Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PeterT
        wrote on last edited by PeterT
        #3

        Thanks Lorn, I was suspecting a wrong url for the audio resource, but might be something else...
        I could post/send my Qt project somewhere if this helps?

        1 Reply Last reply
        0
        • lorn.potterL Offline
          lorn.potterL Offline
          lorn.potter
          wrote on last edited by
          #4

          For anyone else having this issue, here's the bug report:
          https://bugreports.qt.io/browse/QTBUG-104045

          Freelance Software Engineer, Platform Maintainer QtWebAssembly, Maintainer QtSensors
          Author, Hands-On Mobile and Embedded Development with Qt 5 http://bit.ly/HandsOnMobileEmbedded

          1 Reply Last reply
          2
          • P Offline
            P Offline
            PeterT
            wrote on last edited by PeterT
            #5

            Based on the latest comment by Lorn in the above bug report, I tried using QAudioSink instead, and it happened to work!
            This looks like more advanced API, offering more control but also requiring more settings. Perhaps it was considered for audio players usage rather than just sound effects.
            I noticed one defect that may be insignificant while playing long tracks, but that makes it (by me) unsuitable for sound effects is that it adds a short "pop" sound. On Windows target it's at the end of the playback, on WebAssembly it appears both at the beginning and at the end of the playback. Could be related to the interpretation of the audio data length in the buffer, I'm trying to find a way to set some offset as a workaround, if possible at all.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PeterT
              wrote on last edited by
              #6

              Small correction, as others might face the same issue: in more complex application QAudioSink also fails to work (but works when compiled for Windows target). Based on the latest comment by Lorn in the corresponding bug report, Qt Multimedia for WebAssembly requires threaded build. I am trying to get this, will keep this thread posted when more results are available.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved