1

I have only one mp3 file paying in background. I want that mp3 file to played till I close the application. What I am facing is that the mp3 file is played for only once and then stops. I want it to be played again. Find sample code below

Code:

QMediaPlayer *music = new QMediaPlayer();
music->setMedia(QUrl("qrc:/sounds/bgsound.mp3"));
music->setVolume(20);
music->play();

Thanks in advance!!

  • Have you checked `QMediaPlayer`'s API for anyhing useful for that? – Ulrich Eckhardt Jun 08 '20 at 05:30
  • See the answer of [this question](https://stackoverflow.com/questions/37690616/play-background-music-in-a-loop-qt). It's a bit bigger example, containing the method `QMediaPlaylist::setPlaybackMode(QMediaPlaylist::Loop)`, which you might be interested in as well. –  Jun 08 '20 at 19:26
  • I tried this earlier but it did not solve my problem – PreetamShetty Jun 09 '20 at 06:30

1 Answers1

0

Simply do it by connecting signals and slots as follows:

connect(music,&QMediaPlayer::mediaStatusChanged,music,&QMediaPlayer::play);