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. Audio element not working? How to play from resource?
Forum Updated to NodeBB v4.3 + New Features

Audio element not working? How to play from resource?

Scheduled Pinned Locked Moved QML and Qt Quick
14 Posts 8 Posters 9.9k 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.
  • J Offline
    J Offline
    jkosonen
    wrote on last edited by
    #3

    [quote author="Chuck Gao" date="1310954575"]What's the error? Can not find files?[/quote]

    It's mute. If I use soundeffect it works, but then I can't change the volume.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chuck Gao
      wrote on last edited by
      #4

      I think it's a problem with path, there is no error(Output to the console) about this ?

      Chuck

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jkosonen
        wrote on last edited by
        #5

        [quote author="Chuck Gao" date="1311045100"]I think it's a problem with path, there is no error(Output to the console) about this ?[/quote]

        There's no error with path, since if I change it to SoundEffect it works..

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AlterX
          wrote on last edited by
          #6

          I've a similar problem...
          On Symbian^3 and Harmattan if i embed the qml in the resource, sounds (using SoundEffect) don't hear!
          If i load qml as a local file, sounds work, but no images are loaded from the resource!!!

          Qt Ambassador
          Real-time cooperative teams: http://www.softairrealfight.net
          Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

          https://codereview.qt-project.org/...

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pscanlan
            wrote on last edited by
            #7

            I have the same problem and it is not related to the path! It crashed the app.

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nokiadev
              wrote on last edited by
              #8

              Did anyone find a solution yet as I too have the same issue :(

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nokiadev
                wrote on last edited by
                #9

                I have solved this issue by using "file" protocol in audio source

                @Audio {
                id: playSound
                source: "file:///opt/YourProject/sounds/game.mp3"
                }
                @

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kibsoft
                  wrote on last edited by
                  #10

                  I knew about file:///, but is there possibility to play sound from resource file?

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nokiadev
                    wrote on last edited by
                    #11

                    Yes I have played sound from resource file but with some limitations e.g.

                    • sound file size: 70kb approx.

                    • Bit Rate: 8 bit

                    • .wav files only

                    • and the most worst thing is that It plays once.

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      owenzhao
                      wrote on last edited by
                      #12

                      You can leave you sound file outside of resource file, then use
                      @viewer.rootContext()->setContextProperty("installPath", "file:///" + QCoreApplication::applicationDirPath() + "/");@
                      in your main.cpp, make sure this line is before you setsource("main.qml")
                      In you qml code, just use
                      @ Audio {
                      id: playMusicAudio
                      volume: 1.0
                      source: installPath + "sound/youmusic.mp3"
                      }@

                      You need to have this in you app.pro file
                      @# Add more folders to ship with the application, here
                      folder_01.source = qml/yourappname/sound
                      DEPLOYMENTFOLDERS = folder_01@

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        matti-
                        wrote on last edited by
                        #13

                        Perhaps it would be sensible to write a C++ wrapper that would read the mp3 audio file from the resource and feed it to QSound somehow? Is this even an issue anymore? Just stumbled upon this thing today when learning QML - noticed that my Audio {} would not play an .mp3 from within a resource and I'd prefer not to ship separate audio files.

                        I'd bet there already exists a robust solution, will keep googling.

                        edit: Guess I'll try writing a C++ component that wraps the Phonon player. Somehow strange that images work fine from within qrc but not media..?

                        Author of <a href="http://mmark.777-team.org/">MMark13</a>

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          matti-
                          wrote on last edited by
                          #14

                          Doesnt seem to be happening with QMediaPlayer API either.. keep getting QMediaPlayer::FormatError , "Failed to load media" for the qrc sources.

                          Probably could write the resource file into /tmp file and play from there but that would be quite silly. Guess I'll ship the audio files with the app as separate files. :)

                          Author of <a href="http://mmark.777-team.org/">MMark13</a>

                          1 Reply Last reply
                          1

                          • Login

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