PDA

View Full Version : QMediaplayer Sound file problem



digimonkey
11th March 2015, 09:35
Hello,

I have a problem with QMediaPlayer play sound in a different PC than in the developed one.
The release program works just fine in the PC that I have developed (I've copied all *.dll,...), but trying to use the same program in a different PC there is no sound.
I have my sounds in my Resources and their are together with the images that I use, so it isn't path fail.

I create in the header (*.h) file my QMediaPlayer variable:

QMediaPlayer * ErrorSound;


At cpp, in the constructer, I load the sounds:

ErrorSound = new QMediaPlayer();
ErrorSound->setMedia(QUrl("qrc:/Error.wav"));

Further in the correct place I call it to play:

ErrorSound->play();

I've checked the Data.qrc (my resource file) and all files are there:
<RCC>
<qresource prefix="/">
.......other files
<file>Error.wav</file>
</qresource>
</RCC>

All image files and sound files are in same place, same folder, as the *.exe file.

If anyone got this problem and know how to fix it i would thank you for helping me out.

sherifomran
4th February 2018, 06:33
In the header define the following


private:
QPointer <QMediaPlayer> mp3backgroundplayer;


signals:

void playmp3background();
void stopmp3background();



in the code use this to load it from the resource file



QPointer <QMediaPlayer> mp3backgroundplayer = new QMediaPlayer (this);
// ...
mp3backgroundplayer->setMedia(QUrl("qrc:/spacegame/images/gamemedia/spacegamebackground.mp3"));
mp3backgroundplayer->setVolume(30);
mp3backgroundplayer->l

mp3backgroundplayer->play();
connect(this,SIGNAL(playmp3background()),mp3backgr oundplayer.data(),SLOT(play()));
connect(this, SIGNAL(stopmp3background()), mp3backgroundplayer.data(), SLOT(stop()));



to stop use this


this.emit(stopmp3background());


good luck