Check if QMediaPlayer playing content
I have programmed a function play music using QMediaPlayer, and I connected the function with pushbutton, when I press the button more than once the music file playing while the first times are still playing, so I need to check if QMediaPlayer is playing content then I could stop the current music and replay the music file.
widget.h
private slots:
void play_music();
widget.cpp
void Widget::play_music() {
QAudioOutput *outPut = new QAudioOutput;
QMediaPlayer *player = new QMediaPlayer;
player->setAudioOutput(outPut);
player->setSource(QUrl::fromLocalFile("E:\\n8mat alphone\\24.mp3"));
outPut->setVolume(50);
player->setLoops(-1);
outPut->setMuted(false);
player->play();
}
Comments
Post a Comment