summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/snippets/audio/main.cpp109
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo.cpp6
-rw-r--r--src/multimedia/audio/qaudioformat.cpp3
-rw-r--r--src/multimedia/audio/qaudioinput.cpp7
-rw-r--r--src/multimedia/audio/qaudiooutput.cpp7
5 files changed, 127 insertions, 5 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"
+
diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp
index e349733..e38a91e 100644
--- a/src/multimedia/audio/qaudiodeviceinfo.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo.cpp
@@ -71,7 +71,11 @@ QT_BEGIN_NAMESPACE
audio plugins installed and the audio device capabilities. If you need a specific format, you can check if
the device supports it with isFormatSupported(), or fetch a
supported format that is as close as possible to the format with
- nearestFormat().
+ nearestFormat(). For instance:
+
+ \snippet doc/src/snippets/audio/main.cpp 1
+ \dots 8
+ \snippet doc/src/snippets/audio/main.cpp 2
A QAudioDeviceInfo is constructed with a QAudioDeviceId, which is
an identifier for a physical device. It is used by Qt to construct
diff --git a/src/multimedia/audio/qaudioformat.cpp b/src/multimedia/audio/qaudioformat.cpp
index ddfcc2c..c23e454 100644
--- a/src/multimedia/audio/qaudioformat.cpp
+++ b/src/multimedia/audio/qaudioformat.cpp
@@ -134,7 +134,8 @@ public:
through functions in QAudioDeviceInfo. This class also lets you
query available parameter values for a device, so that you can set
the parameters yourself. See the QAudioDeviceInfo class
- description for details.
+ description for details. You need to know the format of the audio
+ streams you wish to play. Qt does not set up formats for you.
*/
/*!
diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp
index edf6dd6..3c0d98e 100644
--- a/src/multimedia/audio/qaudioinput.cpp
+++ b/src/multimedia/audio/qaudioinput.cpp
@@ -128,7 +128,12 @@ QT_BEGIN_NAMESPACE
which states the QAudioInput has been in.
If an error should occur, you can fetch its reason with error().
- The possible error reasons are described by the QAudio::Error enum.
+ The possible error reasons are described by the QAudio::Error
+ enum. The QAudioInput will enter the \l{QAudio::}{StopState} when
+ an error is encountered. Connect to the stateChanged() signal to
+ handle the error:
+
+ \snippet doc/src/snippets/audio/main.cpp 0
\sa QAudioOutput, QAudioDeviceInfo
*/
diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp
index 556b616..8a8edb4 100644
--- a/src/multimedia/audio/qaudiooutput.cpp
+++ b/src/multimedia/audio/qaudiooutput.cpp
@@ -129,9 +129,12 @@ QT_BEGIN_NAMESPACE
If an error occurs, you can fetch the \l{QAudio::Error}{error
type} with the error() function. Please see the QAudio::Error enum
- for a description of the possible errors that are reported.
+ for a description of the possible errors that are reported. When
+ an error is encountered, the state changes to QAudio::StopState.
+ You can check for errors by connecting to the stateChanged()
+ signal:
- If an error is encountered state changes to QAudio::StopState.
+ \snippet doc/src/snippets/audio/main.cpp 3
\sa QAudioInput, QAudioDeviceInfo
*/