Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [solved] Sounds on Android?
Forum Updated to NodeBB v4.3 + New Features

[solved] Sounds on Android?

Scheduled Pinned Locked Moved Mobile and Embedded
11 Posts 4 Posters 6.6k 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.
  • E Offline
    E Offline
    evocat
    wrote on last edited by
    #1

    Hi,
    does somebody know why I'm getting this error when trying to play a sound on Android?

    W/Qt (16485): audio\qsoundeffect_qaudio_p.cpp:354 (void PrivateSoundSource::decoderError()): QSoundEffect(qaudio): Error decoding source

    I am using QSound like:

    @#include <QSound>

    ...

    QSound::play("../sounds/mysound.wav");@

    and mysound.wav-file is located as "../sounds/mysound.wav" states. And everything works perfectly on Windows. What could be wrong?

    Should I possibly configure .pro-file somehow to make sounds deploy with app?

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

      Hi,

      Are you really sure the file can be found on Android ?

      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
      • E Offline
        E Offline
        evocat
        wrote on last edited by
        #3

        No, I'm not sure. I don't know if Qt copies that file automatically on Android device or not.

        But if it doesn't, then what should I do to fix it?

        I would like to configure Qt to somehow copy that file for me, because in the future I need to make a complete .apk file, which should contain everything that my app needs for running correctly.

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

          "this":https://community.kde.org/Necessitas/Assets might help

          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
          • E Offline
            E Offline
            evocat
            wrote on last edited by
            #5

            Thanks!

            With the keyword "assets", I found this link:
            http://qt-project.org/doc/qt-5/platform-notes-android.html

            So, I created assets-folder under myproject/android/, and moved sounds there, and now they DO work on my phone when I call
            @ QSound::play( "assets:/sounds/mysound.wav );@

            There is just one drawback - that broke sounds on my Windows environment.
            .
            .
            .
            Is there any elegant way to tell Qt to call
            @ QSound::play( "assets:/sounds/mysound.wav );@
            in Android, and
            @ QSound::play( "../my/path/sounds/mysound.wav " );@
            in Windows?
            .
            .
            .
            p.s. Even QSound::play("android/assets/sounds/mysound.wav "); won't work in Windows. The problem seems to be related to ./android-path, because sounds in other directories do work. Any ideas why?

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

              You can use

              @#ifdef Q_OS_ANDROID
              QString mySoundPath = "assets:/sounds/mysound.wav";
              #else
              QString mySoundPath = "../my/path/sounds/mysound.wav";
              #endif
              QSound::play(mySoundPath);
              @

              You are giving a relative path, so the folders containing your sound should be at the same level as you executable, which is not the case using a shadow build

              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
              • E Offline
                E Offline
                evocat
                wrote on last edited by
                #7

                Once again, your solution worked - thanks!

                But how I should reference to my sounds directory on Windows, then?

                Until now, I have used "../sounds/", which is working, because my sounds are one directory upper than my code files. But when I build the app, the .exe will go two directories lower than sounds directory. And it still works.

                I don't understand?

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

                  Good question, maybe you have a copy at the right place ? Or the working directory is modified somehow ?

                  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
                  • H Offline
                    H Offline
                    habamax
                    wrote on last edited by
                    #9

                    [quote author="evocat" date="1407009118"]Once again, your solution worked - thanks! But how I should reference to my sounds directory on Windows, then? Until now, I have used "../sounds/", which is working, because my sounds are one directory upper than my code files. But when I build the app, the .exe will go two directories lower than sounds directory. And it still works. I don't understand? [/quote]

                    Why wouldn't you use Qt resource file then? It perfectly works with linux and android without any source code changes. I believe windows is not a problem too.

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

                      Sure it works on all platform. What must be taken in account now is the size of the audio files. wav being uncompressed it can quickly be too big to be used in a builtin resource file.

                      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
                      • N Offline
                        N Offline
                        nologinma
                        wrote on last edited by
                        #11

                        Good work!!! I have I had the same problem.

                        To resume the steps are the following:

                        1. add multimedia in .pro file

                        @QT += core gui multimedia@

                        1. add QSound in the mainwindow.h

                        @#include <QSound>@

                        1. add your sound file under the directory android\sounds (not mandatory)

                        android\sounds\mysound.wav

                        1. add the mysound.wav as resource then create a resource.qrc file and put inside the file mysound.wav

                        2. in your code load the file in this way:

                        @sound = new QSound(":/sounds/done.wav");@

                        1. play the file in this way:

                        @sound->play();@

                        There are several methods as stop(), loop() etc.....

                        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