Fix file path bug in audiorecorder example
authorAndy Nichols <andy.nichols@digia.com>
Thu, 11 Apr 2013 23:20:06 +0000 (16:20 -0700)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 16 Apr 2013 11:38:43 +0000 (13:38 +0200)
Default path and name of the output wave audio files were wrong.  This
means the files did not have the right name to be opened on Windows, and
did not have the right path because they were being saved to the root
folder. (C:/ on windows, and / on OSX).  Now we fall back to the default
filepath and name when we try to record without giving a path and
filename.

Task-number: QTBUG-28663
Change-Id: I8c782a31710cac65cd3c1ecd44de10b41c46e93d
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
examples/multimedia/audiorecorder/audiorecorder.cpp
examples/multimedia/audiorecorder/audiorecorder.h

index ac84768..5f3b0a1 100644 (file)
@@ -172,9 +172,6 @@ void AudioRecorder::toggleRecord()
     if (audioRecorder->state() == QMediaRecorder::StoppedState) {
         audioRecorder->setAudioInput(boxValue(ui->audioDeviceBox).toString());
 
-        if (!outputLocationSet)
-            audioRecorder->setOutputLocation(generateAudioFilePath());
-
         QAudioEncoderSettings settings;
         settings.setCodec(boxValue(ui->audioCodecBox).toString());
         settings.setSampleRate(boxValue(ui->sampleRateBox).toInt());
@@ -214,24 +211,6 @@ void AudioRecorder::displayErrorMessage()
     ui->statusbar->showMessage(audioRecorder->errorString());
 }
 
-QUrl AudioRecorder::generateAudioFilePath()
-{
-    QDir outputDir(QDir::rootPath());
-
-    int lastImage = 0;
-    int fileCount = 0;
-    foreach (const QString &fileName, outputDir.entryList(QStringList(QString("testclip_*")))) {
-        int imgNumber = fileName.mid(5, fileName.size() - 9).toInt();
-        lastImage = qMax(lastImage, imgNumber);
-        if (outputDir.exists(fileName))
-            fileCount += 1;
-    }
-    lastImage += fileCount;
-    QUrl location(QDir::toNativeSeparators(outputDir.canonicalPath()
-        + QString("/testclip_%1").arg(lastImage + 1, 4, 10, QLatin1Char('0'))));
-    return location;
-}
-
 // This function returns the maximum possible sample value for a given audio format
 qreal getPeakValue(const QAudioFormat& format)
 {
index 22cce4b..1a12031 100644 (file)
@@ -71,7 +71,6 @@ private slots:
     void updateState(QMediaRecorder::State);
     void updateProgress(qint64 pos);
     void displayErrorMessage();
-    QUrl generateAudioFilePath();
 
 private:
     Ui::AudioRecorder *ui;