Files:
This example shows how to create a simple audio recorder using the QtMobility Multimedia API.
We can easily setup the capture when we create the objects using a QMediaRecorder initialized with a QAudioCaptureSource object.
audiosource = new QAudioCaptureSource; capture = new QMediaRecorder(audiosource);
Then we set up the display of a list of available sources to use
for(int i = 0; i < audiosource->deviceCount(); i++) deviceBox->addItem(audiosource->name(i));
And available codecs
QStringList codecs = capture->supportedAudioCodecs(); for(int i = 0; i < codecs.count(); i++) codecsBox->addItem(codecs.at(i));
We display a dialog for the user to select the appropriate codec and the input device to capture. Once selected we can use user interface objects like buttons to start and stop the recording and display elapsed time.
for(int i = 0; i < audiosource->deviceCount(); i++) { if(deviceBox->itemText(idx).compare(audiosource->name(i)) == 0) audiosource->setSelectedDevice(i); }
Then use signals to indicate a change to the output filename, the codec and the audio source.
When the button to record is pushed the toggleRecord() slot will start or stop the recording process using the QMediaRecorder::record() and QMediaRecorder::stop() functions of the QMediaRecorder object.
void AudioRecorder::toggleRecord() { if(!active) { recTime->setText("0 sec"); currentTime = 0; capture->record(); button->setText(tr("Stop")); active = true; } else { capture->stop(); button->setText(tr("Record")); active = false; } }
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.