-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.cpp
61 lines (49 loc) · 1.23 KB
/
dialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
player = new QMediaPlayer(this);
connect(player, &QMediaPlayer::positionChanged, this, &Dialog::on_positionChanged);
connect(player, &QMediaPlayer::durationChanged, this, &Dialog::on_durationChanged);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_sliderVolume_sliderMoved(int position)
{
player->setVolume(position);
}
void Dialog::on_sliderProgress_sliderMoved(int position)
{
player->setPosition(position);
}
void Dialog::on_startButton_clicked()
{
// load the file
if(songName != "") {
qDebug() << "Playing: "<<songName;
player->setMedia(QUrl::fromLocalFile(songName));
player->play();
}
qDebug() << "Error: "<<player->errorString();
}
void Dialog::on_stopButton_clicked()
{
player->stop();
}
void Dialog::on_positionChanged(qint64 position)
{
ui->sliderProgress->setValue(position);
}
void Dialog::on_durationChanged(qint64 position)
{
ui->sliderProgress->setMaximum(position);
}
void Dialog::on_browseButton_clicked()
{
songName = QFileDialog::getOpenFileName(this, "Open a file...", "Audio File (mp3)");
}