Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Media Player Start/Pause/Stop
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Media Player Start/Pause/Stop

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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?

    Regards

    This is how my source for play/stop looks like... So far it only disable a button, but not also stop playing a song...

    @void MainWindow::on_play_clicked()
    {

    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);
    

    }

    void MainWindow::on_Stop_clicked()
    {

    ui->Stop->setEnabled(false);
    ui->Play->setEnabled(true);
    

    }
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thanks ! Fixed.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
          {
          ui->setupUi(this);
          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)));
          

          }@

          @void MainWindow::on_Playlist_clicked()
          {
          QString directory = QFileDialog::getExistingDirectory(this,tr("Select dir for files to import"));
          if(directory.isEmpty())
          return;
          QDir dir(directory);
          QStringList files = dir.entryList(QStringList() << "*.mp3",QDir::Files);
          QList<QMediaContent> content;
          for(const QString& f:files)
          {
          content.push_back(QUrl::fromLocalFile(dir.path()+"/" + f));
          QFileInfo fi(f);
          ui->listWidget->addItem(fi.fileName());
          }
          //ui->listWidget->setCurrentRow(playlist->currentIndex() != -1? playlist->currentIndex():0);
          // playlist->addMedia(content);
          }
          @

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Sloved !

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved