Breaking out of QMediaPlaylist with setPlaybackMode set to inf loop
Hi everyone,
Is this possible?
Im trying:
Code:
bool MainWindow::on_checkBox_clicked()
{
QString alarmTime
= QString::number(this
->ui
->timeEdit
->time
().
hour()) + QString::number(this
->ui
->timeEdit
->time
().
minute());
QMediaPlaylist *playlist = new QMediaPlaylist(this);
playlist
->addMedia
(QUrl::fromLocalFile("/path/song.mp3"));
playlist->setPlaybackMode(QMediaPlaylist::Loop);
playlist->setCurrentIndex(1);
QMediaPlayer *player = new QMediaPlayer(this);
player->setPlaylist(playlist);
player->setVolume(100);
if(this->ui->checkBox_2->isChecked() == false)
{
if(alarmTime == currentTime)
{
player->play();
}
}
else
if(this->ui->checkBox_2->isChecked() == true)
{
playlist->stop();
}
}
It starts playing fine, but when I click the appropriate check box to stop it, it does not. Any thoughts on how I can get this to work properly?
Thank you!!!
Re: Breaking out of QMediaPlaylist with setPlaybackMode set to inf loop
Maybe I'm understanding this wrong but it looks like you're creating a new player/playlist each time you click, and you actually want to stop the player from the last or first click. Maybe use a global player, or at least point to one?
Re: Breaking out of QMediaPlaylist with setPlaybackMode set to inf loop
Indeed.
Let playlist be a member of MainWindow and in the slot you just call play() or stop(), depending on the checkbox's state.
Cheers,
_