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. Strange problem with QMediaPlayer on Windows (URGENT)

Strange problem with QMediaPlayer on Windows (URGENT)

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.8k 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.
  • Z Offline
    Z Offline
    zarnick
    wrote on last edited by
    #1

    Hy, I'm using Qt 5.0.2 and QMediaPlayer to play a wav sound, I've decided to stop trying using QSound or QSoundEffect, since they would simply not play the wav sound, and show no errors.
    However, here's the strange thing, if I start the program via QtCreator, no problem, QMediaPlayer works as expected, however, if I start it outside the QtCreator, it simply won't play the sound!
    I'm actually doing a fairly standar thing:
    On the class constructor I start the sound:
    (where _player is declared as QMediaPlayer *_player)
    @
    QString hornSound = QDir::currentPath().append("/horn.wav");
    _player = new QMediaPlayer(this);
    _player->setMedia(QUrl::fromLocalFile(hornSound));
    @

    and when I need to use it I use the play method:
    @
    _player->play();
    @

    Can anyone help me out on this? This is kinda urgent.

    Thanks

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

      Hi,

      Make sure that your horn.war is in the current working directory, otherwise, you should not use QDir::currentPath().

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zarnick
        wrote on last edited by
        #3

        The sound is correctly in place, I've double checked it at runtime. And it has the correct permissions.

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

          Hi,

          Are you sure that the CWD used when your start your application under Qt Creator is the same as the CWD when you start it outside the QtCreator ?

          Can you show us your application file structure, or simple output the CWD in both cases?

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zarnick
            wrote on last edited by
            #5

            I've place this on the start of the first GUI of the program:
            @QString hornSound = QDir::currentPath().append("/horn.wav");
            QMediaPlayer player;
            player.setMedia(QUrl::fromLocalFile(hornSound));
            player.setVolume(100);
            player.play();
            QMessageBox::information(this,tr("horn"),hornSound);
            QMessageBox::information(this,tr("available"),player.isAudioAvailable()?tr("True"):tr("False"));
            QMessageBox::information(this,tr("available"),player.isAvailable()?tr("True"):tr("False"));@

            The output I have when I run it from the QtCreator is this:
            "C:/Users/minterciso/Documents/Programacao/qt/inlinespeedtracker/build-InlineSpeedTracker-Desktop_Qt_5_0_2_MinGW_32bit-Release/horn.wav"
            and afterwards True, True. and the sounds is played.

            If I start it from the release subdirectory, it shows "C:/Users/minterciso/Documents/Programacao/qt/inlinespeedtracker/build-InlineSpeedTracker-Desktop_Qt_5_0_2_MinGW_32bit-Release/release/horn.wav" and False, False, and the sound does not play.
            And yes, the file horn.wav is on both directories.

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zarnick
              wrote on last edited by
              #6

              Well, digging a little more I found a way to make QSound work as intended from this post http://stackoverflow.com/questions/14165608/qt5-qsound-does-not-play-all-wave-files .
              Basically recreating the WAV file worked like a charm and QSound is now working again, and this time is better then using QMediaPlayer for this.

              It still puzzels me why QMediaPlayer has this strange behaviour on Windows, but at least for my problem, this is solved.

              Thanks for the help.

              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