Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to play a wav file that is defined in resource file

how to play a wav file that is defined in resource file

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 4.8k Views
  • 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    eveyrthing is old in google search, and QSound::play(":/sounds/sound1") doesn't work.

    any solution?

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

      Hi,

      What's your Qt version ?
      On what OS ?

      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
      • U user4592357

        eveyrthing is old in google search, and QSound::play(":/sounds/sound1") doesn't work.

        any solution?

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @user4592357

        It was clearly not possible to do so in earlier Qt versions, see: https://bugreports.qt.io/browse/QTBUG-9253

        I cannot tell you if that has changed, though.

        Qt has to stay free or it will die.

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

          From a quick look at the sources of QSound, it seems to still be the case, but it can be worked around using QTemporaryFile for example.

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

          U 1 Reply Last reply
          1
          • SGaistS SGaist

            From a quick look at the sources of QSound, it seems to still be the case, but it can be worked around using QTemporaryFile for example.

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @SGaist
            like this?

            auto player = new QMediaPlayer(this);
            player->setMedia(QUrl::fromLocalFile(QTemporaryFile(":/sounds/sound1").fileName()));
            player->play();
            

            doesn't work though

            aha_1980A 1 Reply Last reply
            0
            • U user4592357

              @SGaist
              like this?

              auto player = new QMediaPlayer(this);
              player->setMedia(QUrl::fromLocalFile(QTemporaryFile(":/sounds/sound1").fileName()));
              player->play();
              

              doesn't work though

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @user4592357

              I guess you will have to create a temp file, copy the contents from the resource file to the temp file and then open the temp file.

              You can get some inspiration from here: http://www.qtcentre.org/threads/18644-QSound-and-embedded-resources

              but I would not take it directly as it does not seem to operate on a temp directory. and operating on the program directory is forbidden on most operating systems.

              Regards

              Qt has to stay free or it will die.

              1 Reply Last reply
              3
              • aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi again @user4592357

                In case you are still interested, I just tried myself and a simple QSound::play(":/claves.wav"); did work for me.

                There was no need to create temporary files.

                Regards

                Qt has to stay free or it will die.

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

                  I've created a documentation update: https://codereview.qt-project.org/224476 to explicitely state that playing from resources is possible nowadays.

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  3

                  • Login

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