Qt World Summit: Register Today!

Strange problem with QMediaPlayer on Windows (URGENT)

  • 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);

    and when I need to use it I use the play method:

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


  • Hi,

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

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

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

  • I've place this on the start of the first GUI of the program:
    @QString hornSound = QDir::currentPath().append("/horn.wav");
    QMediaPlayer player;

    The output I have when I run it from the QtCreator is this:
    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.

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

Log in to reply