-
Notifications
You must be signed in to change notification settings - Fork 2
/
AudioNoteEditor.cpp
110 lines (90 loc) · 3.03 KB
/
AudioNoteEditor.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "AudioNoteEditor.h"
#include "AudioNote.h"
#include <QWidget>
#include <QFileDialog>
#include <QPushButton>
#include <QVBoxLayout>
#include <QUrl>
#include <QProgressBar>
AudioNoteEditor::AudioNoteEditor(AudioNote* a, QWidget *parent)
:BinaryEditor(a, parent), ressource(a)
{
btnAddAudio = new QPushButton("Choose a Song");
player = new QMediaPlayer;
playlist = new QMediaPlaylist(player);
if(!ressource->getMediaPath().isNull())
{
playlist->addMedia(QUrl::fromLocalFile(ressource->getMediaPath()));
player->setMedia(QUrl::fromLocalFile(ressource->getMediaPath()));
playlist->setCurrentIndex(0);
player->setPlaylist(playlist);
play = false;
btnPlayPause = new QPushButton("PLay/Pause");
btnStop = new QPushButton("Stop");
btnStop->resize(32,32);
btnStop->setIcon(QIcon(":images/stop"));
progression = new QProgressBar;
progression->setMinimum(0);
progression->setMaximum(100);
btnPlayPause->setIcon(QIcon(":images/play"));
QObject::connect(btnPlayPause, SIGNAL(clicked()), this, SLOT(PLAY_PAUSE_SONG()));
QObject::connect(btnStop, SIGNAL(clicked()), this, SLOT(STOP_SONG()));
QObject::connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(SET_VALUE(qint64)));
}
btnLine = new QHBoxLayout;
contentLayout->addWidget(progression);
contentLayout->addLayout(btnLine);
btnLine->addWidget(btnPlayPause);
btnLine->addWidget(btnStop);
contentLayout->addWidget(new QLabel("Description:"));
contentLayout->addWidget(getDescriptionWidget());
buttonsLayout->addWidget(btnAddAudio);
QObject::connect(btnAddAudio, SIGNAL(clicked()), this, SLOT(LOAD_AUDIO()));
QObject::connect(this, SIGNAL(destroyed()), this, SLOT(CLOSING()));
}
AudioNoteEditor::~AudioNoteEditor(){
player->stop();
}
void AudioNoteEditor::CLOSING()
{
player->stop();
}
void AudioNoteEditor::BACKEND_SET_CONTENT()
{
ressource->setDescription(getDescriptionWidget()->text());
ressource->setMediaPath(ressource->getMediaPath());
}
void AudioNoteEditor::LOAD_AUDIO(){
ressource->setMediaPath(QFileDialog::getOpenFileName(this, "Ouvrir un fichier", QString(), "Audio (*.mp3 *.ogg)"));
qDebug()<<ressource->getMediaPath();
player->setMedia(QMediaContent(QUrl::fromLocalFile(ressource->getMediaPath())));
player->setMedia(QUrl::fromLocalFile(ressource->getMediaPath()));
play = false;
}
void AudioNoteEditor::PLAY_PAUSE_SONG()
{
if(ressource->getMediaPath().isEmpty())
return;
if(play)
{
player->pause();
btnPlayPause->setIcon(QIcon(":images/play"));
play = false;
}
else
{
player->play();
btnPlayPause->setIcon(QIcon(":images/pause"));
play = true;
}
}
void AudioNoteEditor::STOP_SONG()
{
player->stop();
}
void AudioNoteEditor::SET_VALUE(qint64 val)
{
qDebug()<<val << "/"<<player->duration();
qDebug()<< "=" << val/player->duration();
progression->setValue(val*100/player->duration());
}