Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-updates > by-pkgid > 1680fb88efc4e76ac8cb0ebf3578014f > files > 344

qtmultimedia5-doc-5.12.6-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- audiorecorder.qdoc -->
  <title>Audio Recorder Example | Qt Multimedia 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtmultimedia-index.html">Qt Multimedia</a></td><td ><a href="multimedia-examples.html">Qt Multimedia Examples</a></td><td >Audio Recorder Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtmultimedia-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#displaying-the-window-and-audio-settings">Displaying the Window and Audio Settings</a></li>
<li class="level1"><a href="#recording-audio">Recording Audio</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Audio Recorder Example</h1>
<span class="subtitle"></span>
<!-- $$$multimedia/audiorecorder-brief -->
<p>Discovering the available devices and supported codecs.</p>
<!-- @@@multimedia/audiorecorder -->
<!-- $$$multimedia/audiorecorder-description -->
<div class="descr"> <a name="details"></a>
<p><i>Audio Recorder</i> demonstrates how to identify the available devices and supported codecs, and the use of <a href="qaudiorecorder.html">QAudioRecorder</a> class.</p>
<p class="centerAlign"><img src="images/audiorecorder.png" alt="" /></p><a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<a name="displaying-the-window-and-audio-settings"></a>
<h2 id="displaying-the-window-and-audio-settings">Displaying the Window and Audio Settings</h2>
<p>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.</p>
<p>The lists are setup using the <a href="qaudiorecorder.html#audioInputs">audioInputs()</a>, <a href="qmediarecorder.html#supportedAudioCodecs">supportedAudioCodecs()</a>, <a href="qmediarecorder.html#supportedContainers">supportedContainers()</a>, <a href="qmediarecorder.html#supportedContainers">supportedContainers()</a>, and <a href="qmediarecorder.html#supportedAudioSampleRates">supportedAudioSampleRates()</a> methods. The quality slider is setup from 0 (zero) to <a href="qmultimedia.html#EncodingQuality-enum">QMultimedia::VeryHighQuality</a> with a default value of <a href="qmultimedia.html#EncodingQuality-enum">QMultimedia::NormalQuality</a>, while the bitrates are hardcoded into the list.</p>
<a name="recording-audio"></a>
<h2 id="recording-audio">Recording Audio</h2>
<p>To record audio we simply create a <a href="qaudiorecorder.html">QAudioRecorder</a> object.</p>
<pre class="cpp">

  audioRecorder <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaudiorecorder.html">QAudioRecorder</a></span>(<span class="keyword">this</span>);

</pre>
<p>And setup the lists as described above. The text on the record and pause buttons are toggled depending on the <a href="qmediarecorder.html#State-enum">state</a> of the <code>audioRecorder</code> object. This means that if the state is <a href="qmediarecorder.html#State-enum">QMediaRecorder::StoppedState</a> then the button text will be &quot;Record&quot; and &quot;Pause&quot;. In <a href="qmediarecorder.html#State-enum">QMediaRecorder::RecordingState</a> the record button will have the text &quot;Stop&quot;, and in <a href="qmediarecorder.html#State-enum">QMediaRecorder::PausedState</a> the pause button will have the text &quot;Resume&quot;.</p>
<p>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 <a href="qaudioencodersettings.html">QAudioEncoderSettings</a> based on the values of the selection lists, will set the encoding settings and container on the <code>audioRecorder</code> object, and start recording using the <a href="qmediarecorder.html#record">record()</a> method.</p>
<pre class="cpp">

  <span class="type"><a href="qaudioencodersettings.html">QAudioEncoderSettings</a></span> settings;
  settings<span class="operator">.</span>setCodec(boxValue(ui<span class="operator">-</span><span class="operator">&gt;</span>audioCodecBox)<span class="operator">.</span>toString());
  settings<span class="operator">.</span>setSampleRate(boxValue(ui<span class="operator">-</span><span class="operator">&gt;</span>sampleRateBox)<span class="operator">.</span>toInt());
  settings<span class="operator">.</span>setBitRate(boxValue(ui<span class="operator">-</span><span class="operator">&gt;</span>bitrateBox)<span class="operator">.</span>toInt());
  settings<span class="operator">.</span>setQuality(<span class="type"><a href="qmultimedia.html">QMultimedia</a></span><span class="operator">::</span>EncodingQuality(ui<span class="operator">-</span><span class="operator">&gt;</span>qualitySlider<span class="operator">-</span><span class="operator">&gt;</span>value()));
  settings<span class="operator">.</span>setEncodingMode(ui<span class="operator">-</span><span class="operator">&gt;</span>constantQualityRadioButton<span class="operator">-</span><span class="operator">&gt;</span>isChecked() <span class="operator">?</span>
                           <span class="type"><a href="qmultimedia.html">QMultimedia</a></span><span class="operator">::</span>ConstantQualityEncoding :
                           <span class="type"><a href="qmultimedia.html">QMultimedia</a></span><span class="operator">::</span>ConstantBitRateEncoding);

  <span class="type">QString</span> container <span class="operator">=</span> boxValue(ui<span class="operator">-</span><span class="operator">&gt;</span>containerBox)<span class="operator">.</span>toString();

  audioRecorder<span class="operator">-</span><span class="operator">&gt;</span>setEncodingSettings(settings<span class="operator">,</span> <span class="type"><a href="qvideoencodersettings.html">QVideoEncoderSettings</a></span>()<span class="operator">,</span> container);
  audioRecorder<span class="operator">-</span><span class="operator">&gt;</span>record();

</pre>
<p>While recording, the status bar of the application is updated with duration information from the <a href="qmediarecorder.html#durationChanged">durationChanged</a> signal from the <code>audioRecorder</code> object.</p>
<pre class="cpp">

  ui<span class="operator">-</span><span class="operator">&gt;</span>statusbar<span class="operator">-</span><span class="operator">&gt;</span>showMessage(tr(<span class="string">&quot;Recorded %1 sec&quot;</span>)<span class="operator">.</span>arg(duration <span class="operator">/</span> <span class="number">1000</span>));

</pre>
<p>Files:</p>
<ul>
<li><a href="qtmultimedia-multimedia-audiorecorder-audiolevel-cpp.html">multimedia/audiorecorder/audiolevel.cpp</a></li>
<li><a href="qtmultimedia-multimedia-audiorecorder-audiolevel-h.html">multimedia/audiorecorder/audiolevel.h</a></li>
<li><a href="qtmultimedia-multimedia-audiorecorder-audiorecorder-cpp.html">multimedia/audiorecorder/audiorecorder.cpp</a></li>
<li><a href="qtmultimedia-multimedia-audiorecorder-audiorecorder-h.html">multimedia/audiorecorder/audiorecorder.h</a></li>
<li><a href="qtmultimedia-multimedia-audiorecorder-audiorecorder-pro.html">multimedia/audiorecorder/audiorecorder.pro</a></li>
<li><a href="qtmultimedia-multimedia-audiorecorder-audiorecorder-ui.html">multimedia/audiorecorder/audiorecorder.ui</a></li>
<li><a href="qtmultimedia-multimedia-audiorecorder-main-cpp.html">multimedia/audiorecorder/main.cpp</a></li>
</ul>
</div>
<!-- @@@multimedia/audiorecorder -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>