QtMobility Reference Documentation

Audio Recorder Example


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++)

And available codecs

     QStringList codecs = capture->supportedAudioCodecs();
     for(int i = 0; i < codecs.count(); 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)

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;

         active = true;
     } else {
         active = false;

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.