PDA

View Full Version : Breaking out of QMediaPlaylist with setPlaybackMode set to inf loop



lupo5
11th May 2014, 20:43
Hi everyone,

Is this possible?

Im trying:


bool MainWindow::on_checkBox_clicked()
{


QString alarmTime = QString::number(this->ui->timeEdit->time().hour()) + QString::number(this->ui->timeEdit->time().minute());
QString currentTime = QString::number(QTime::currentTime().hour()) + QString::number(QTime::currentTime().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!!!

sulliwk06
12th May 2014, 13:07
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?

anda_skoa
12th May 2014, 14:06
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,
_