summaryrefslogtreecommitdiffstats
path: root/examples/multimedia
diff options
context:
space:
mode:
authorPekka Gehör <pekka.gehor@qt.io>2021-10-22 13:52:45 +0300
committerPekka Gehör <pekka.gehor@qt.io>2021-11-09 12:18:09 +0200
commit24d80c6a7856547036c36b719ca9aba6bb59b815 (patch)
treefb05d844fd45ec3d9cf50d97b6715843f25c44d4 /examples/multimedia
parent0c1bb90691780703eabc7ed1954d6b49fe5da580 (diff)
Android: Fix for Content uri issues
After fix file name and file extension will pass as a initial name to the file name field of the QFileDialog. Fixes: QTBUG-96957 Pick-to: 6.2 Change-Id: Iea97b1249195fee1021163beb23130141093c3a4 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'examples/multimedia')
-rw-r--r--examples/multimedia/audiorecorder/audiorecorder.cpp20
-rw-r--r--examples/multimedia/audiorecorder/audiorecorder.h1
2 files changed, 17 insertions, 4 deletions
diff --git a/examples/multimedia/audiorecorder/audiorecorder.cpp b/examples/multimedia/audiorecorder/audiorecorder.cpp
index d8ad6467d..992e0a486 100644
--- a/examples/multimedia/audiorecorder/audiorecorder.cpp
+++ b/examples/multimedia/audiorecorder/audiorecorder.cpp
@@ -64,6 +64,7 @@
#include <qaudiobuffer.h>
#include <qaudioinput.h>
#include <qimagecapture.h>
+#include <QMimeType>
static QList<qreal> getBufferLevels(const QAudioBuffer &buffer);
@@ -172,10 +173,7 @@ void AudioRecorder::toggleRecord()
if (m_audioRecorder->recorderState() == QMediaRecorder::StoppedState) {
m_captureSession.audioInput()->setDevice(boxValue(ui->audioDeviceBox).value<QAudioDevice>());
- QMediaFormat format;
- format.setFileFormat(boxValue(ui->containerBox).value<QMediaFormat::FileFormat>());
- format.setAudioCodec(boxValue(ui->audioCodecBox).value<QMediaFormat::AudioCodec>());
- m_audioRecorder->setMediaFormat(format);
+ m_audioRecorder->setMediaFormat(selectedMediaFormat());
m_audioRecorder->setAudioSampleRate(ui->sampleRateBox->value());
m_audioRecorder->setAudioBitRate(boxValue(ui->bitrateBox).toInt());
m_audioRecorder->setAudioChannelCount(boxValue(ui->channelsBox).toInt());
@@ -201,7 +199,13 @@ void AudioRecorder::togglePause()
void AudioRecorder::setOutputLocation()
{
+#ifdef Q_OS_ANDROID
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save Recording"),
+ "output."
+ + selectedMediaFormat().mimeType().preferredSuffix());
+#else
QString fileName = QFileDialog::getSaveFileName();
+#endif
m_audioRecorder->setOutputLocation(QUrl::fromLocalFile(fileName));
m_outputLocationSet = true;
}
@@ -254,6 +258,14 @@ void AudioRecorder::clearAudioLevels()
m_audioLevel->setLevel(0);
}
+QMediaFormat AudioRecorder::selectedMediaFormat() const
+{
+ QMediaFormat format;
+ format.setFileFormat(boxValue(ui->containerBox).value<QMediaFormat::FileFormat>());
+ format.setAudioCodec(boxValue(ui->audioCodecBox).value<QMediaFormat::AudioCodec>());
+ return format;
+}
+
// returns the audio level for each channel
QList<qreal> getBufferLevels(const QAudioBuffer &buffer)
{
diff --git a/examples/multimedia/audiorecorder/audiorecorder.h b/examples/multimedia/audiorecorder/audiorecorder.h
index 071b8510e..9ef20f0d5 100644
--- a/examples/multimedia/audiorecorder/audiorecorder.h
+++ b/examples/multimedia/audiorecorder/audiorecorder.h
@@ -86,6 +86,7 @@ private slots:
private:
void clearAudioLevels();
+ QMediaFormat selectedMediaFormat() const;
Ui::AudioRecorder *ui = nullptr;