Fix file path bug in audiorecorder example

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>
This commit is contained in:
Andy Nichols
2013-04-11 16:20:06 -07:00
committed by The Qt Project
parent f2af807c5b
commit 315bcd0758
2 changed files with 0 additions and 22 deletions

View File

@@ -172,9 +172,6 @@ void AudioRecorder::toggleRecord()
if (audioRecorder->state() == QMediaRecorder::StoppedState) { if (audioRecorder->state() == QMediaRecorder::StoppedState) {
audioRecorder->setAudioInput(boxValue(ui->audioDeviceBox).toString()); audioRecorder->setAudioInput(boxValue(ui->audioDeviceBox).toString());
if (!outputLocationSet)
audioRecorder->setOutputLocation(generateAudioFilePath());
QAudioEncoderSettings settings; QAudioEncoderSettings settings;
settings.setCodec(boxValue(ui->audioCodecBox).toString()); settings.setCodec(boxValue(ui->audioCodecBox).toString());
settings.setSampleRate(boxValue(ui->sampleRateBox).toInt()); settings.setSampleRate(boxValue(ui->sampleRateBox).toInt());
@@ -214,24 +211,6 @@ void AudioRecorder::displayErrorMessage()
ui->statusbar->showMessage(audioRecorder->errorString()); 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 // This function returns the maximum possible sample value for a given audio format
qreal getPeakValue(const QAudioFormat& format) qreal getPeakValue(const QAudioFormat& format)
{ {

View File

@@ -71,7 +71,6 @@ private slots:
void updateState(QMediaRecorder::State); void updateState(QMediaRecorder::State);
void updateProgress(qint64 pos); void updateProgress(qint64 pos);
void displayErrorMessage(); void displayErrorMessage();
QUrl generateAudioFilePath();
private: private:
Ui::AudioRecorder *ui; Ui::AudioRecorder *ui;