-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
72 lines (48 loc) · 1.42 KB
/
Copy pathmainwindow.cpp
File metadata and controls
72 lines (48 loc) · 1.42 KB
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
62
63
64
65
66
67
68
69
70
71
72
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qpushbutton.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qmediaplayer.h>
#include <qaudiooutput.h>
#include <qurl.h>
#include <qslider.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
//Label
ui->setupUi(this);
QLabel *Label = new QLabel("input open File:",this);
Label -> move(10,10);
//input
QLineEdit *Edit = new QLineEdit(this);
Edit -> move(115,10);
//Button show
QPushButton *Button = new QPushButton("Play",this);
Button -> move(340,500);
QPushButton *Button_STOP = new QPushButton("Stop",this);
Button_STOP -> move(450,500);
QMediaPlayer *player = new QMediaPlayer;
QAudioOutput *audio = new QAudioOutput(this);
player->setAudioOutput(audio);
//player->setAudioOutput(new QAudioOutput);
QSlider *Volume = new QSlider(Qt::Horizontal,this);
Volume->setGeometry(50,100,200,30);
Volume ->setRange(0,100);
Volume ->setValue(50);
connect(Button,&QPushButton::clicked,this,[=](){
player->setSource(QUrl::fromLocalFile(Edit->text()));
player->play();
});
connect(Volume,&QSlider::valueChanged,this,[=](int value){
audio->setVolume(value/100.0);
});
connect(Button_STOP,&QPushButton::clicked,this,[=](){
player->stop();
});
}
MainWindow::~MainWindow()
{
delete ui;
}