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



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



  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.