blob: a215d43fcad1cc0467dbe3e6ea4d44da007f5959 (
plain)
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 <QtGui>
#include <QAudioOutput>
#include <QAudioDeviceInfo>
#include <QAudioInput>
class Window2 : public QWidget
{
Q_OBJECT
public slots:
//![0]
void stateChanged(QAudio::State newState)
{
switch(newState) {
case QAudio::StopState:
if (input->error() != QAudio::NoError) {
// Error handling
} else {
}
break;
//![0]
default:
;
}
}
private:
QAudioInput *input;
};
class Window : public QWidget
{
Q_OBJECT
public:
Window()
{
output = new QAudioOutput;
connect(output, SIGNAL(stateChanged(QAudio::State)),
this, SLOT(stateChanged(QAudio::State)));
}
private:
void setupFormat()
{
//![1]
QAudioFormat format;
format.setFrequency(44100);
//![1]
format.setChannels(2);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
//![2]
format.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceId id = QAudioDeviceInfo::defaultOutputDevice();
QAudioDeviceInfo info(id);
if (!info.isFormatSupported(format))
format = info.nearestFormat(format);
//![2]
}
public slots:
//![3]
void stateChanged(QAudio::State newState)
{
switch (newState) {
case QAudio::StopState:
if (output->error() != QAudio::NoError) {
// Do your error handlin
} else {
// Normal stop
}
break;
//![3]
// Handle
case QAudio::ActiveState:
// Handle active state...
break;
break;
default:
;
}
}
private:
QAudioOutput *output;
};
int main(int argv, char **args)
{
QApplication app(argv, args);
Window window;
window.show();
return app.exec();
}
#include "main.moc"
|