[SOLVED] Media Player Start/Pause/Stop
Hello, I am playing around with Qt and trying to create Media Player. So my problem is when I start playing a song, I can't stop it. I don't know how to stop it nor pause it. Any suggestions how to do that??? I guess threads??? Or some other way?
This is how my source for play/stop looks like... So far it only disable a button, but not also stop playing a song...
QMediaPlayer *player = new QMediaPlayer(this); player->setMedia(QUrl::fromLocalFile("Made in the USA.mp3")); player->setVolume(100); player->play(); ui->Play->setEnabled(false); ui->Stop->setEnabled(true);
Have a look at the "Media Player Example":http://qt-project.org/doc/qt-5.0/qtmultimedia/multimediawidgets-player.html it shows what you're looking for
Thanks ! Fixed.
Hey, another problem... I am trying to add PlayList and It add list in my listWidget, but it won't play it... I know problem is in last two comment lines but don't know how to solve that... If I uncomment that, it will say "playlist not defined"
@MainWindow::MainWindow(QWidget *parent) :
QMediaPlayer *player = new QMediaPlayer(this);
QMediaPlaylist *playlist = new QMediaPlaylist(player);
player->setPlaylist(playlist); player->setVolume(35); playlist->addMedia(playlist); connect(ui->Play, SIGNAL(clicked()), player, SLOT(play())); connect(ui->Pause, SIGNAL(clicked()), player, SLOT(pause())); connect(ui->Stop, SIGNAL(clicked()), player, SLOT(stop())); connect(ui->Volume, SIGNAL(sliderMoved(int)), player, SLOT(setVolume(int)));
QString directory = QFileDialog::getExistingDirectory(this,tr("Select dir for files to import"));
QStringList files = dir.entryList(QStringList() << "*.mp3",QDir::Files);
for(const QString& f:files)
content.push_back(QUrl::fromLocalFile(dir.path()+"/" + f));
//ui->listWidget->setCurrentRow(playlist->currentIndex() != -1? playlist->currentIndex():0);