Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to play a .wav file in QT6?
Forum Updated to NodeBB v4.3 + New Features

How to play a .wav file in QT6?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 1.5k 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.
  • ndiasN Offline
    ndiasN Offline
    ndias
    wrote on last edited by
    #1

    Hi,

    I am unable to play a audio file in QT6. I get this error message:

    QSoundEffect(qaudio): Error decoding source ./sounds/clock-alarm-beep.wav
    

    when I use code bellow:

    import QtQuick
    import QtQuick.Controls
    
    import QtMultimedia
    
    ApplicationWindow {
        visible: true
        width: 400
        height: 600
    
        SoundEffect {
            id: alarmSound
            //source: "qrc:/sounds/clock-alarm-beep.wav"
            source: "./sounds/pager-beeps.wav"
            //source: "C:/Users/ndias/Desktop/AnalogClock/sounds/clock-alarm-beep.wav"
        }
        MouseArea {
            id: playArea
            anchors.fill: parent
            onPressed: { console.info("PLAY"); alarmSound.play(); }
        }
    }
    

    I tried to run this sample code on QT5 without any success except when I use the Audio module instead of SoundEffect and using an absolute source URL of the wav file.
    Using SoundEffect in QT5 I same error and using Audio module with QRC or relative path source I get no errors but I was unable to play the file.

    Can anyone give me clarifications on how to overcome this problem?

    Best regards


    PS: QT6 does not have Audio module

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by
      #2

      The chances are, the bitrate of the wav file is not in accordance with requirements. Perhaps a wav with 22000hz is not decodable but a wav at 48000hz is. Check your source file.

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      1 Reply Last reply
      0
      • ndiasN Offline
        ndiasN Offline
        ndias
        wrote on last edited by
        #3

        Tested with 48kHz sampling rate wav files unsuccessfully (https://www.kozco.com/tech/soundtests.html). I got the same behavior as described in first topic.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Did you upgrade Qt to 6.2 ?

          That said, when using relative paths, did you ensure that the files are stored in the same folder as your application executable ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • ndiasN Offline
            ndiasN Offline
            ndias
            wrote on last edited by ndias
            #5

            Hi @SGaist,

            I tested it using Qt 6.2 and Qt 5.15.2.

            I copied .wav file to same folder application executable file. I forgot this detail before. But I still did not succeed to play wav file.

            So this moment I am able only to play wav files using absolute source URL when using Audio module (Qt5).

            EDIT: I have no problems when using QRC on Android build (Audio and SoundEffect types) 🙂

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What if you drop the "./" in the path ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              ndiasN 1 Reply Last reply
              0
              • SGaistS SGaist

                What if you drop the "./" in the path ?

                ndiasN Offline
                ndiasN Offline
                ndias
                wrote on last edited by
                #7

                @SGaist said in How to play a .wav file in QT6?:

                What if you drop the "./" in the path ?

                I get the same result.


                Meanwhile I've been testing the compilation on Android with different sample rates. I get the following warning on the console output if audio file does not contain a 48000Hz sample rate. Despite this, .wav file is played.

                W AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 44100 Hz, output 48000 Hz
                

                Regards

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  On which platform does it fail ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • ndiasN Offline
                    ndiasN Offline
                    ndias
                    wrote on last edited by
                    #9

                    Hi @SGaist

                    I am using Windows platform.

                    For Qt5, I tested it with:

                    • Qt5.15.2 MinGW 32-bit
                    • Pyside 2

                    For Qt6, I used:

                    • qmlscene.exe (6.2.0 MinGW 64-bit) --- Not tested with Qt6.2 MinGW because "QtMultimedia is not currently supported on this platform or compiler"
                    • Pyside 6.2
                    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