QMediaPlayer doesn't play sound 6.6.3
-
I've tried every variation, doesn't want to play sound no matter what I do
player = new QMediaPlayer; audioOutput = new QAudioOutput; player->setAudioOutput(new QAudioOutput); // ... player->setSource(QUrl::fromLocalFile(":/sounds/boom.mp3")); audioOutput->setVolume(50); player->play();
-
@Dilabun How about adding error handling (https://doc.qt.io/qt-6/qmediaplayer.html#errorOccurred)?
-
@Dilabun
Do you mean you have tried it with other Qt versions and it works but not with 6.6.3, or you just happen to be using 6.6.3 and it does not work?Have you connected the
mediaStatusChanged()
anderrorOccurred()
signals for information?I assume your file is a Qt resource file, right? What does
qDebug() << QUrl::fromLocalFile(":/sounds/boom.mp3")
show? Have you tried eitherqrc:/sounds/boom.mp3
orqrc:///sounds/boom.mp3
? Otherwise I suggest you read through Audio not playing from .qrc resources and see whether the various proposals there resolve. -
I have Question.
Is it correct ?
audioOutput = new QAudioOutput; player->setAudioOutput(new QAudioOutput); // Is it correct ?
as per my knowledge it should be like this
audioOutput = new QAudioOutput; player->setAudioOutput(audioOutput);
-
@Dilabun
I had not looked closely at your code, but what @Ketan__Patel__0011 has written is certainly correct. If that is really the code you have been trying you have created two quite separateQAudioOutput
s. The one inaudioOutput
whose volume you set is not the one which isplayer
's output. So start by sorting that out!