Reputation: 1
I want to record and save audio in a file. Here is the code is use:
QAudioEncoderSettings audioSettings;
audioSettings.setCodec("audio/pcm");
audioSettings.setQuality(QMultimedia::HighQuality);
audioRecorder.setEncodingSettings(audioSettings);
dir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).value(0);
QString qdir = dir.path();
qdir.append(QString("/test.wav"));
audioRecorder.setOutputLocation(QUrl::fromLocalFile(qdir));
audioRecorder.record();
This works perfectly fine on windows. I can record, save and play the sound without any problems. As soon as i try this code on androind i get:
D MediaRecorder: getMaxAllowedFileSizeByPath
D MediaRecorder: no match storage volume found!
I set the required storage and record permissions. The phone i am trying to run the code on is a HTC one M8 (Anroid version 6.0)
I tried to create a file manually, but this doesn't work either.
QDir folder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
QString qdir = folder.path();
qdir.append(QString("/transmission.wav"));
QFile file(qdir);
if (file.exists())
file.remove();
qDebug() << "file exists: " << file.exists();
if (!file.exists()) {
if (!folder.exists()) {
folder.mkpath(folder.path());
}
file.open(QIODevice::WriteOnly);
file.write("Hello World");
file.close();
}
if (file.exists()) {
qDebug() << "file exists: " << file.exists();
file.open(QIODevice::ReadOnly);
QByteArray data=file.readAll();
qWarning("file data=%s",data.constData());
file.close();
}
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) gives back: storage/0/emulated/Documents
file.open(QIODevice::ReadOnly) gives back QIODevice::write (QFile, "/storage/emulated/0/Documents/transmission.wav"): device not open
Looks like the recorder is not able to create a file - nor am i.
Upvotes: 0
Views: 583