summaryrefslogtreecommitdiff
path: root/examples/multimedia
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@digia.com>2014-09-24 16:40:21 +0200
committerYoann Lopes <yoann.lopes@digia.com>2014-09-26 14:23:20 +0200
commit5c30ed55ef41ea85232f63c7ee4fd52a4e7126e2 (patch)
tree3f052ea304cf36c56daab8c6250653aec88563eb /examples/multimedia
parentf9de9889f6b909968f31743ab60e66dd356f2a4d (diff)
downloadqtmultimedia-5c30ed55ef41ea85232f63c7ee4fd52a4e7126e2.tar.gz
Improve audiorecorder example.
- Show actual recording location - Update control buttons depending on the recorder state instead of the status - Create audio levels using the actual audio format from the audio buffers. The format from the QMediaRecorder might not always contain the value actually used. Task-number: QTBUG-36154 Change-Id: I418b4472b0d984f47efb1a1813da6ef440ba9a40 Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Diffstat (limited to 'examples/multimedia')
-rw-r--r--examples/multimedia/audiorecorder/audiorecorder.cpp57
-rw-r--r--examples/multimedia/audiorecorder/audiorecorder.h1
2 files changed, 34 insertions, 24 deletions
diff --git a/examples/multimedia/audiorecorder/audiorecorder.cpp b/examples/multimedia/audiorecorder/audiorecorder.cpp
index 2291fed52..7d942255a 100644
--- a/examples/multimedia/audiorecorder/audiorecorder.cpp
+++ b/examples/multimedia/audiorecorder/audiorecorder.cpp
@@ -114,6 +114,8 @@ AudioRecorder::AudioRecorder(QWidget *parent) :
SLOT(updateProgress(qint64)));
connect(audioRecorder, SIGNAL(statusChanged(QMediaRecorder::Status)), this,
SLOT(updateStatus(QMediaRecorder::Status)));
+ connect(audioRecorder, SIGNAL(stateChanged(QMediaRecorder::State)),
+ this, SLOT(onStateChanged(QMediaRecorder::State)));
connect(audioRecorder, SIGNAL(error(QMediaRecorder::Error)), this,
SLOT(displayErrorMessage()));
}
@@ -138,47 +140,44 @@ void AudioRecorder::updateStatus(QMediaRecorder::Status status)
switch (status) {
case QMediaRecorder::RecordingStatus:
- if (audioLevels.count() != audioRecorder->audioSettings().channelCount()) {
- qDeleteAll(audioLevels);
- audioLevels.clear();
- for (int i = 0; i < audioRecorder->audioSettings().channelCount(); ++i) {
- QAudioLevel *level = new QAudioLevel(ui->centralwidget);
- audioLevels.append(level);
- ui->levelsLayout->addWidget(level);
- }
- }
-
- ui->recordButton->setText(tr("Stop"));
- ui->pauseButton->setText(tr("Pause"));
- if (audioRecorder->outputLocation().isEmpty())
- statusMessage = tr("Recording");
- else
- statusMessage = tr("Recording to %1").arg(
- audioRecorder->outputLocation().toString());
+ statusMessage = tr("Recording to %1").arg(audioRecorder->actualLocation().toString());
break;
case QMediaRecorder::PausedStatus:
clearAudioLevels();
- ui->recordButton->setText(tr("Stop"));
- ui->pauseButton->setText(tr("Resume"));
statusMessage = tr("Paused");
break;
case QMediaRecorder::UnloadedStatus:
case QMediaRecorder::LoadedStatus:
clearAudioLevels();
- ui->recordButton->setText(tr("Record"));
- ui->pauseButton->setText(tr("Pause"));
statusMessage = tr("Stopped");
default:
break;
}
- ui->pauseButton->setEnabled(audioRecorder->state()
- != QMediaRecorder::StoppedState);
-
if (audioRecorder->error() == QMediaRecorder::NoError)
ui->statusbar->showMessage(statusMessage);
}
+void AudioRecorder::onStateChanged(QMediaRecorder::State state)
+{
+ switch (state) {
+ case QMediaRecorder::RecordingState:
+ ui->recordButton->setText(tr("Stop"));
+ ui->pauseButton->setText(tr("Pause"));
+ break;
+ case QMediaRecorder::PausedState:
+ ui->recordButton->setText(tr("Stop"));
+ ui->pauseButton->setText(tr("Resume"));
+ break;
+ case QMediaRecorder::StoppedState:
+ ui->recordButton->setText(tr("Record"));
+ ui->pauseButton->setText(tr("Pause"));
+ break;
+ }
+
+ ui->pauseButton->setEnabled(audioRecorder->state() != QMediaRecorder::StoppedState);
+}
+
static QVariant boxValue(const QComboBox *box)
{
int idx = box->currentIndex();
@@ -347,6 +346,16 @@ QVector<qreal> getBufferLevels(const T *buffer, int frames, int channels)
void AudioRecorder::processBuffer(const QAudioBuffer& buffer)
{
+ if (audioLevels.count() != buffer.format().channelCount()) {
+ qDeleteAll(audioLevels);
+ audioLevels.clear();
+ for (int i = 0; i < buffer.format().channelCount(); ++i) {
+ QAudioLevel *level = new QAudioLevel(ui->centralwidget);
+ audioLevels.append(level);
+ ui->levelsLayout->addWidget(level);
+ }
+ }
+
QVector<qreal> levels = getBufferLevels(buffer);
for (int i = 0; i < levels.count(); ++i)
audioLevels.at(i)->setLevel(levels.at(i));
diff --git a/examples/multimedia/audiorecorder/audiorecorder.h b/examples/multimedia/audiorecorder/audiorecorder.h
index 2c0a1e5ed..9d013ae7c 100644
--- a/examples/multimedia/audiorecorder/audiorecorder.h
+++ b/examples/multimedia/audiorecorder/audiorecorder.h
@@ -71,6 +71,7 @@ private slots:
void toggleRecord();
void updateStatus(QMediaRecorder::Status);
+ void onStateChanged(QMediaRecorder::State);
void updateProgress(qint64 pos);
void displayErrorMessage();