To write the C++ code for music players, perform the following steps:
- First and foremost, open up mainwindow.h and add the following headers:
#include <QMainWindow> #include <QDebug> #include <QFileDialog> #include <QMediaPlayer> #include <QMediaMetaData> #include <QTime>
- After that, add the player variable, which is a QMediaPlayer pointer. Then, declare the functions that we're going to define later:
private: Ui::MainWindow *ui; QMediaPlayer* player; public: void stateChanged(QMediaPlayer::State state); void positionChanged(qint64 position);
- Next, open up mainwindow.cpp and initialize the player variable:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ...