summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorGeir Vattekar <geir.vattekar@trolltech.com>2009-09-15 11:01:45 (GMT)
committerGeir Vattekar <geir.vattekar@trolltech.com>2009-09-15 11:03:34 (GMT)
commitcd5f0f868bc830c6b350e8263fd53597f52e1146 (patch)
tree1306128003e1ca96546515c96ea6802ff4c56fe8 /doc
parent2b21c3f4022c64ee6f0178b1866f22639c377ae6 (diff)
downloadQt-cd5f0f868bc830c6b350e8263fd53597f52e1146.zip
Qt-cd5f0f868bc830c6b350e8263fd53597f52e1146.tar.gz
Qt-cd5f0f868bc830c6b350e8263fd53597f52e1146.tar.bz2
Doc: Added some snippets to the multimedia audio docs.
Diffstat (limited to 'doc')
-rw-r--r--doc/src/snippets/audio/main.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/doc/src/snippets/audio/main.cpp b/doc/src/snippets/audio/main.cpp
new file mode 100644
index 0000000..a215d43
--- /dev/null
+++ b/doc/src/snippets/audio/main.cpp
@@ -0,0 +1,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"
+