3 Attachment(s)
QMediaPlayer crash using QPlaylist
Hello,
so i want to run background music on loop and i searched for it on how to do it on google and i found this bit of code:
Code:
playlist = new QMediaPlaylist();
playlist
->addMedia
(QUrl("qrc:/World_Sounds/BackgroundSound.wav"));
playlist->setPlaybackMode(QMediaPlaylist::Loop);
music = new QMediaPlayer();
music->setPlaylist(playlist);
music->play();
but this code crashes as soon as the first song stops playing ? (when it wants to loop)
but doing only this works, but the problem is it won't loop the media:
Code:
music = new QMediaPlayer();
music
->setMedia
(QUrl("qrc:/World_Sounds/BackgroundSound.wav"));
music->play();
Here is the error message:
Attachment 13370
More error messages:
https://imgur.com/P0c8UKh
If anyone knows why does this happen, please help :(
Any help is appreciated !!!!
Re: QMediaPlayer crash using QPlaylist
Hello,
I faced the same issue recently using Qt5.12.9, before that the code you provided worked fine.
What I actually did is... I gave up from using QMediaPlaylist and used QMediaPlayer::stateChanged signal instead.
In your case it should be something like:
Code:
music = new QMediaPlayer();
music
->setMedia
(QUrl("qrc:/World_Sounds/BackgroundSound.wav"));
connect(music, &QMediaPlayer::stateChanged, [this](QMediaPlayer::State state) {
if (state == QMediaPlayer::State::StoppedState)
{
music->play();
}
});
music->play();
Hope it may help.