One dedicated file per voice note recording

This commit is contained in:
Sebastian Wolf 2021-01-04 22:03:04 +01:00
parent 81ffb53062
commit e0b94a0487
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
3 changed files with 23 additions and 7 deletions

View file

@ -151,6 +151,9 @@ Item {
anchors.fill: parent
onClicked: {
recordButton.visible = false;
recordingDone = false;
recordingDuration = 0;
handleRecordingDuration();
fernschreiberUtils.startRecordingVoiceNote();
}
}

View file

@ -23,8 +23,10 @@
#include <QAudioEncoderSettings>
#include <QStandardPaths>
#include <QDir>
#include <QDirIterator>
#include <QFile>
#include <QUrl>
#include <QDateTime>
#include <QGeoCoordinate>
#include <QGeoLocation>
@ -35,7 +37,7 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent)
{
LOG("Initializing audio recorder...");
QString temporaryDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + + "/harbour-fernschreiber";
QString temporaryDirectoryPath = this->getTemporaryDirectoryPath();
QDir temporaryDirectory(temporaryDirectoryPath);
if (!temporaryDirectory.exists()) {
temporaryDirectory.mkpath(temporaryDirectoryPath);
@ -47,7 +49,6 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent)
encoderSettings.setQuality(QMultimedia::LowQuality);
this->audioRecorder.setEncodingSettings(encoderSettings);
this->audioRecorder.setContainerFormat("ogg");
this->audioRecorder.setOutputLocation(QUrl::fromLocalFile(temporaryDirectoryPath + "/voicenote.ogg"));
QMediaRecorder::Status audioRecorderStatus = this->audioRecorder.status();
this->handleAudioRecorderStatusChanged(audioRecorderStatus);
@ -194,7 +195,8 @@ QString FernschreiberUtils::getUserName(const QVariantMap &userInformation)
void FernschreiberUtils::startRecordingVoiceNote()
{
LOG("Start recording voice note...");
this->cleanUp();
QDateTime thisIsNow = QDateTime::currentDateTime();
this->audioRecorder.setOutputLocation(QUrl::fromLocalFile(this->getTemporaryDirectoryPath() + "/voicenote-" + thisIsNow.toString("yyyy-MM-dd-HH-mm-ss") + ".ogg"));
this->audioRecorder.setVolume(1);
this->audioRecorder.record();
}
@ -287,9 +289,19 @@ void FernschreiberUtils::cleanUp()
if (this->geoPositionInfoSource) {
this->geoPositionInfoSource->stopUpdates();
}
QString voiceNotePath = this->voiceNotePath();
if (QFile::exists(voiceNotePath)) {
LOG("Removing old temporary file...");
QFile::remove(voiceNotePath);
QString temporaryDirectoryPath = this->getTemporaryDirectoryPath();
QDirIterator temporaryDirectoryIterator(temporaryDirectoryPath, QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks, QDirIterator::Subdirectories);
while (temporaryDirectoryIterator.hasNext()) {
QString nextFilePath = temporaryDirectoryIterator.next();
if (QFile::remove(nextFilePath)) {
LOG("Temporary file removed " << nextFilePath);
} else {
LOG("Error removing temporary file " << nextFilePath);
}
}
}
QString FernschreiberUtils::getTemporaryDirectoryPath()
{
return QStandardPaths::writableLocation(QStandardPaths::TempLocation) + + "/harbour-fernschreiber";
}

View file

@ -69,6 +69,7 @@ private:
QGeoPositionInfoSource *geoPositionInfoSource;
void cleanUp();
QString getTemporaryDirectoryPath();
};