Audio Recorder ExampleFiles:
This example shows how to create a simple audio recorder using the Qt Mobility 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-2010 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 X
|