Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. N900 and QMediaPlayer
Qt 6.12 LTS is out! See what's new in the release blog

N900 and QMediaPlayer

Scheduled Pinned Locked Moved Mobile and Embedded
14 Posts 4 Posters 9.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I got this bit of code that I run on a N900 with PR1.3 Qt4.7 Mobility 1.0.2

    @
    QMediaPlayer *player = new QMediaPlayer;
    player->setMedia(QUrl::fromLocalFile("ballhit.wav"));
    player->setVolume(50);
    player->play();
    @

    When I run it, this happends:

    bq. GStreamer; Unable to play - "file:ballhit.wav"

    I think that it may not find the file, I have tried many different methods of adding the wav file to my project, but none seems to work, I don't know what is the best approach.
    If i replace "ballhit.wav" with for example: "Http://tst.com/b.wav", it works, no problem.
    But I can't load my sound files from the web, I want them on the device.

    Developing on windows with Qt Creator.

    Please help me :)

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      have you tried absolute path instead of relative? maybe your file is in wrong dir?

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I don't know the absolute path, I hope this can work with the relative path so it will work on other platforms as well... Anyway, what will my absolute path be?

        I think I need some step by step guide here, cause I feel like I have tried it all.. :(

        Thank you for your replay :)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          Then at first try to discover is this relative path valid (QFile or QFileInfo will help you).

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Great tip, thank you :)

            I did this:
            @
            QFileInfo fi;
            fi.setFile("ballhit.wav");
            bool tst = fi.isFile();
            @

            fi.isFile() returned false..

            What now?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              Now you should investigate what relative path you should give for your file to find it. If you will provide more info about source of this file, how do you receive its name and other related things then it will be easier to help you.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Okay, I have done the following:

                In the same folder as src.pro i got ballhit.wav, and in src.pro i added this:

                OTHER_FILES += ballhit.wav

                target.path = $$DESTDIR
                target.files += ballhit.wav
                INSTALLS += target

                I have also added a build step: "make install"

                I have also included it on my resource file, but this does not seem to work(?)

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  As far as I know playing sound from resources is not supported, at least not with QSound.

                  From the documentation:
                  Note that QSound does not support resources. This might be fixed in a future Qt version.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DenisKormalev
                    wrote on last edited by
                    #9

                    for using files from resources you need to add ":/" or "qrc:/" to your filename. But not aware about playing sound from resources (simply never tried)

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #10

                      I know that QSound does not support resources, so I really didn't bother too much about the resources, but I did try to use :/ and qrc://, did not work..

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #11

                        I have found the path of the executable to be: "/usr/local/bin/" but there is no "ballhit.wav" in that dir.

                        1 Reply Last reply
                        0
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #12

                          I did a "find . -name "ballhit.wav"" with root and found nothing on the phone.
                          So, the file has not been copied ?
                          How can I ensure the file is copied and installed with the executable?

                          1 Reply Last reply
                          0
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #13

                            Problem solved!
                            Solution: "http://talk.maemo.org/showpost.php?p=855984&postcount=9":http://talk.maemo.org/showpost.php?p=855984&postcount=9

                            I hope Qt will find a better way to handle this...

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              swhweng
                              wrote on last edited by
                              #14

                              Hello,
                              And how to play the sound in loops ( indefinitly ) using QMediaPlayer as in QSound?
                              Is it possible using QtMobility classes?
                              Thanks.

                              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
                              • Unsolved