summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/audiorecorder/doc/src/audiorecorder.qdoc
blob: a369337e6298232a9d7ec7402ee1a141bf736c9e (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
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.  Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example multimedia/audiorecorder
    \title Audio Recorder Example
    \ingroup multimedia_examples
    \brief The Audio Recorder Example shows how to create a simple audio recorder.

    It demonstrates the discovery of the supported devices and codecs and the use
    of recording functions in the QAudioRecorder class.

    We display a window for the user to select the appropriate audio input,
    codec, container, and sample rate. Allow a setting of either quality or
    bitrate. Finally, the output file can be selected and recording can be
    started.

    The lists are setup using the \l{QAudioRecorder::audioInputs()}{audioInputs()},
    \l{QAudioRecorder::supportedAudioCodecs()}{supportedAudioCodecs()},
    \l{QAudioRecorder::supportedContainers()}{supportedContainers()},
    \l{QAudioRecorder::supportedContainers()}{supportedContainers()}, and
    \l{QAudioRecorder::supportedAudioSampleRates()}{supportedAudioSampleRates()}
    methods. The quality slider is setup from 0 (zero) to
    \l{QMultimedia::VeryHighQuality} with a default value of
    \l{QMultimedia::NormalQuality}, while the bitrates are hardcoded
    into the list.

    \image audiorecorder.png

    To record audio we simply create a QAudioRecorder object.

    \code
    audioRecorder = new QAudioRecorder(this);
    \endcode

    And setup the lists as described above. The text on the record and pause
    buttons are toggled depending on the \l{QMediaRecorder::State}{state} of
    the \c audioRecorder object. This means that if the state is
    \l{QMediaRecorder::StoppedState} then the button text will be "Record" and
    "Pause". In \l{QMediaRecorder::RecordingState} the record button will have
    the text "Stop", and in \l{QMediaRecorder::PausedState} the pause button
    will have the text "Resume".

    Pressing the buttons will also result in a toggle based on the state. If
    recording is stopped, then pressing the record button will setup the
    \l{QAudioEncoderSettings} based on the values of the selection lists,
    will set the encoding settings and container on the \c audioRecorder
    object, and start recording using the
    \l{QMediaRecorder::record()}{record()} method.

    \code
        QAudioEncoderSettings settings;
        settings.setCodec(boxValue(ui->audioCodecBox).toString());
        settings.setSampleRate(boxValue(ui->sampleRateBox).toInt());
        settings.setBitRate(boxValue(ui->bitrateBox).toInt());
        settings.setQuality(QMultimedia::EncodingQuality(ui->qualitySlider->value()));
        settings.setEncodingMode(ui->constantQualityRadioButton->isChecked() ?
                                 QMultimedia::ConstantQualityEncoding :
                                 QMultimedia::ConstantBitRateEncoding);

        QString container = boxValue(ui->containerBox).toString();

        audioRecorder->setEncodingSettings(settings, QVideoEncoderSettings(), container);
        audioRecorder->record();
    \endcode

    While recording, the status bar of the application is updated with duration information
    from the \l{QMediaRecorder::durationChanged()}{durationChanged} signal from the
    \c audioRecorder object.

    \code
    ui->statusbar->showMessage(tr("Recorded %1 sec").arg(duration / 1000));
    \endcode
*/