0

I have Qt Creator 9.0.2 and I want to add background music to my little project (game).

I've added QT += multimedia

I tried following:

QMediaPlayer* background_music = new QMediaPlayer();

background_music->setMedia(QUrl(..) // there is no setMedia() member function

Then I tried

background_music->setSource(QUrl("qrc:/sounds/sound.mp3"));

background_music->play()

//after a few tries it ran but no music was heard

I don't know what to do Please help.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • Qt creator is an IDE or rather, a glorified editor. It's just what you use to write your code in, it's not some magical environment that enables sound. It doesn't matter whether you write your code in notepad, Emacs or some other editor. Background music needs something more than your ide. – Jesper Juhl Mar 09 '23 at 22:15
  • Have you added `sounds/sound.mp3` to your projects resources? Have you tried listening to the status signals? https://doc.qt.io/qt-6/qmediaplayer.html#setSource – Alan Birtles Mar 09 '23 at 22:43

0 Answers0