Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    3
    8
    3500
    Loading More Posts
    • 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
      user4592357 last edited by

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

      any solution?

      aha_1980 1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • aha_1980
          aha_1980 Lifetime Qt Champion @user4592357 last edited by

          @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 Reply Quote 1
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 1
            • U
              user4592357 @SGaist last edited by

              @SGaist
              like this?

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

              doesn't work though

              aha_1980 1 Reply Last reply Reply Quote 0
              • aha_1980
                aha_1980 Lifetime Qt Champion @user4592357 last edited by

                @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 Reply Quote 3
                • aha_1980
                  aha_1980 Lifetime Qt Champion last edited by

                  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 Reply Quote 0
                  • aha_1980
                    aha_1980 Lifetime Qt Champion last edited by

                    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 Reply Quote 3
                    • First post
                      Last post