diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-01-21 17:41:25 -0500 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-01-21 17:41:25 -0500 |
| commit | 34ca38fefa4bd4bf6177c36f530025a6fe56c558 (patch) | |
| tree | 70f2094d3e7bd08690eb8c402bdd60f7f39cc048 | |
| parent | 22a25303fd71a0c2815af80748492bb705217fc4 (diff) | |
| download | erable-godot-34ca38fefa4bd4bf6177c36f530025a6fe56c558.tar.gz erable-godot-34ca38fefa4bd4bf6177c36f530025a6fe56c558.tar.bz2 erable-godot-34ca38fefa4bd4bf6177c36f530025a6fe56c558.zip | |
Making the file dialog a variable and added stop button
| -rw-r--r-- | player.cpp | 59 | ||||
| -rw-r--r-- | player.h | 4 | ||||
| -rw-r--r-- | player.ui | 92 |
3 files changed, 119 insertions, 36 deletions
@@ -7,16 +7,38 @@ #include <QMessageBox> +void Player::mFileDialog() +{ + QString mFile; + QMessageBox msgbox; + mFile = QFileDialog::getOpenFileName(this, "Open any audio file", QDir::homePath(), tr("Audio Files (*.mp3 *.wav *.ogg)")); + if (mFile == NULL) { + qDebug() << "File cannot be found"; + msgbox.setText("File is invalid."); + msgbox.exec(); + return; + } else { + mPlayer->setMedia(QUrl::fromLocalFile(mFile)); + qDebug() << "Opening" << mFile; + msgbox.setText("This audio file has been loaded."); + msgbox.exec(); + return; + } +} + + + Player::Player(QWidget *parent) : QMainWindow(parent) , ui(new Ui::Player) { ui->setupUi(this); + } Player::~Player() { - qInfo() << "Closing AleePlayer...\n"; + qInfo() << "Closing AleePlayer..."; mPlayer->deleteLater(); delete ui; } @@ -28,15 +50,24 @@ void Player::on_actionQuit_triggered() void Player::on_playButton_pressed() { + QPushButton playButton; if (mPlayer->state() == mPlayer->PlayingState) { qDebug() << "Pausing music..."; mPlayer->pause(); + playButton.setText("Pause"); } else { qDebug() << "Playing music..."; mPlayer->play(); + playButton.setText("Play"); } } +void Player::on_stopButton_pressed() +{ + qInfo() << "Stopping music..."; + mPlayer->stop(); +} + void Player::on_actionAbout_triggered() { qDebug() << "Opening dialog"; @@ -46,32 +77,10 @@ void Player::on_actionAbout_triggered() void Player::on_mediaButton_pressed() { - QString mFile; - QMessageBox msgbox; - mFile = QFileDialog::getOpenFileName(this, "Open any audio file", QDir::homePath(), tr("Audio Files (*.mp3)")); - if (mFile == NULL) { - msgbox.setText("File is invalid."); - return; - } else { - mPlayer->setMedia(QUrl::fromLocalFile(mFile)); - qDebug() << "Opening" << mFile; - msgbox.setText("This audio file has been loaded."); - msgbox.exec(); - } + mFileDialog(); } void Player::on_actionOpen_triggered() { - QString mFile; - QMessageBox msgbox; - mFile = QFileDialog::getOpenFileName(this, "Open any audio file", QDir::homePath(), tr("Audio Files (*.mp3)")); - if (mFile == NULL) { - msgbox.setText("File is invalid."); - return; - } else { - mPlayer->setMedia(QUrl::fromLocalFile(mFile)); - qDebug() << "Opening" << mFile; - msgbox.setText("This audio file has been loaded."); - msgbox.exec(); - } + mFileDialog(); } @@ -28,6 +28,10 @@ private slots: void on_actionOpen_triggered(); + void on_stopButton_pressed(); + + void mFileDialog(); + private: Ui::Player *ui; }; @@ -14,13 +14,29 @@ <string>AleePlayer</string> </property> <widget class="QWidget" name="centralwidget"> - <widget class="QPushButton" name="playButton"> + <widget class="QPushButton" name="mediaButton"> <property name="geometry"> <rect> <x>20</x> - <y>20</y> - <width>88</width> - <height>34</height> + <y>500</y> + <width>80</width> + <height>26</height> + </rect> + </property> + <property name="text"> + <string>Set Media</string> + </property> + <property name="flat"> + <bool>false</bool> + </property> + </widget> + <widget class="QPushButton" name="playButton"> + <property name="geometry"> + <rect> + <x>280</x> + <y>500</y> + <width>80</width> + <height>26</height> </rect> </property> <property name="text"> @@ -32,18 +48,72 @@ <property name="checked"> <bool>false</bool> </property> + <property name="flat"> + <bool>false</bool> + </property> </widget> - <widget class="QPushButton" name="mediaButton"> + <widget class="QSlider" name="volumeSlider"> <property name="geometry"> <rect> - <x>130</x> - <y>20</y> - <width>88</width> - <height>34</height> + <x>560</x> + <y>500</y> + <width>160</width> + <height>31</height> + </rect> + </property> + <property name="value"> + <number>0</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="tickPosition"> + <enum>QSlider::NoTicks</enum> + </property> + <property name="tickInterval"> + <number>0</number> + </property> + </widget> + <widget class="QPushButton" name="stopButton"> + <property name="geometry"> + <rect> + <x>400</x> + <y>500</y> + <width>80</width> + <height>26</height> </rect> </property> <property name="text"> - <string>Set Media</string> + <string>Stop</string> + </property> + <property name="flat"> + <bool>false</bool> + </property> + </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>570</x> + <y>530</y> + <width>58</width> + <height>18</height> + </rect> + </property> + <property name="text"> + <string>Volume</string> + </property> + </widget> + <widget class="QSlider" name="playbackSlider"> + <property name="geometry"> + <rect> + <x>40</x> + <y>445</y> + <width>741</width> + <height>31</height> + </rect> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> </widget> </widget> @@ -53,7 +123,7 @@ <x>0</x> <y>0</y> <width>800</width> - <height>30</height> + <height>23</height> </rect> </property> <widget class="QMenu" name="menuFile"> |
