-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathaudiorecorder.h
88 lines (74 loc) · 1.67 KB
/
audiorecorder.h
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
#ifndef AUDIORECORDER_H
#define AUDIORECORDER_H
#include <QString>
#include <QAudioRecorder>
#include <QAudioEncoderSettings>
class SimpleAudioRecorder : public QObject
{
Q_OBJECT
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
Q_PROPERTY(QString file READ file)
public:
SimpleAudioRecorder(const QString &saveDir);
~SimpleAudioRecorder();
Q_INVOKABLE bool isValid()
{
return m_bValid;
}
QString device()
{
return m_recorder.audioInput();
}
QString codec()
{
return m_settings.codec();
}
int sampleRate()
{
return m_settings.sampleRate();
}
QString container()
{
return m_recorder.containerFormat();
}
int bitrate()
{
return m_settings.bitRate();
}
int channels()
{
return m_settings.channelCount();
}
QMultimedia::EncodingQuality quality()
{
return m_settings.quality();
}
/*
* current record
*/
Q_INVOKABLE void record();
Q_INVOKABLE void stop();
/* return the full path of the current record */
QString file();
qint64 duration();
Q_INVOKABLE bool success();
signals:
void durationChanged(qint64 duration);
protected slots:
void onDurationChanged(qint64 duration);
void onStatusChanged(QMediaRecorder::Status);
void onError(QMediaRecorder::Error);
private:
bool setupRecorder();
private:
QString m_baseDir;
QAudioRecorder m_recorder;
QAudioEncoderSettings m_settings;
bool m_bValid;
QString m_device;
QString m_container;
qint64 m_duration;
bool m_bSuccess;
QString m_filePath;
};
#endif // AUDIORECORDER_H