Update audiooutput example with volume slider
Update example for new volume API Change-Id: I1b9ccbccc62930549e667f0063b3d76feb23a2ea Reviewed-on: http://codereview.qt-project.org/5662 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: derick hawcroft <derick.hawcroft@nokia.com>
This commit is contained in:
@@ -51,6 +51,7 @@ const QString AudioTest::PushModeLabel(tr("Enable push mode"));
|
|||||||
const QString AudioTest::PullModeLabel(tr("Enable pull mode"));
|
const QString AudioTest::PullModeLabel(tr("Enable pull mode"));
|
||||||
const QString AudioTest::SuspendLabel(tr("Suspend playback"));
|
const QString AudioTest::SuspendLabel(tr("Suspend playback"));
|
||||||
const QString AudioTest::ResumeLabel(tr("Resume playback"));
|
const QString AudioTest::ResumeLabel(tr("Resume playback"));
|
||||||
|
const QString AudioTest::VolumeLabel(tr("Volume:"));
|
||||||
|
|
||||||
const int DurationSeconds = 1;
|
const int DurationSeconds = 1;
|
||||||
const int ToneFrequencyHz = 600;
|
const int ToneFrequencyHz = 600;
|
||||||
@@ -190,6 +191,18 @@ void AudioTest::initializeWindow()
|
|||||||
connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume()));
|
connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume()));
|
||||||
layout->addWidget(m_suspendResumeButton);
|
layout->addWidget(m_suspendResumeButton);
|
||||||
|
|
||||||
|
QHBoxLayout *volumeBox = new QHBoxLayout;
|
||||||
|
m_volumeLabel = new QLabel;
|
||||||
|
m_volumeLabel->setText(VolumeLabel);
|
||||||
|
m_volumeSlider = new QSlider(Qt::Horizontal);
|
||||||
|
m_volumeSlider->setMinimum(0);
|
||||||
|
m_volumeSlider->setMaximum(100);
|
||||||
|
m_volumeSlider->setSingleStep(10);
|
||||||
|
connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(volumeChanged(int)));
|
||||||
|
volumeBox->addWidget(m_volumeLabel);
|
||||||
|
volumeBox->addWidget(m_volumeSlider);
|
||||||
|
layout->addLayout(volumeBox);
|
||||||
|
|
||||||
window->setLayout(layout.data());
|
window->setLayout(layout.data());
|
||||||
layout.take(); // ownership transferred
|
layout.take(); // ownership transferred
|
||||||
|
|
||||||
@@ -231,6 +244,7 @@ void AudioTest::createAudioOutput()
|
|||||||
connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
|
connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
|
||||||
m_generator->start();
|
m_generator->start();
|
||||||
m_audioOutput->start(m_generator);
|
m_audioOutput->start(m_generator);
|
||||||
|
m_volumeSlider->setValue(int(m_audioOutput->volume()*100.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioTest::~AudioTest()
|
AudioTest::~AudioTest()
|
||||||
@@ -248,6 +262,12 @@ void AudioTest::deviceChanged(int index)
|
|||||||
createAudioOutput();
|
createAudioOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioTest::volumeChanged(int value)
|
||||||
|
{
|
||||||
|
if (m_audioOutput)
|
||||||
|
m_audioOutput->setVolume(qreal(value/100.0f));
|
||||||
|
}
|
||||||
|
|
||||||
void AudioTest::notified()
|
void AudioTest::notified()
|
||||||
{
|
{
|
||||||
qWarning() << "bytesFree = " << m_audioOutput->bytesFree()
|
qWarning() << "bytesFree = " << m_audioOutput->bytesFree()
|
||||||
|
|||||||
@@ -45,6 +45,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QSlider>
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@@ -94,6 +96,8 @@ private:
|
|||||||
QPushButton* m_modeButton;
|
QPushButton* m_modeButton;
|
||||||
QPushButton* m_suspendResumeButton;
|
QPushButton* m_suspendResumeButton;
|
||||||
QComboBox* m_deviceBox;
|
QComboBox* m_deviceBox;
|
||||||
|
QLabel* m_volumeLabel;
|
||||||
|
QSlider* m_volumeSlider;
|
||||||
|
|
||||||
QAudioDeviceInfo m_device;
|
QAudioDeviceInfo m_device;
|
||||||
Generator* m_generator;
|
Generator* m_generator;
|
||||||
@@ -108,6 +112,7 @@ private:
|
|||||||
static const QString PullModeLabel;
|
static const QString PullModeLabel;
|
||||||
static const QString SuspendLabel;
|
static const QString SuspendLabel;
|
||||||
static const QString ResumeLabel;
|
static const QString ResumeLabel;
|
||||||
|
static const QString VolumeLabel;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void notified();
|
void notified();
|
||||||
@@ -116,6 +121,7 @@ private slots:
|
|||||||
void toggleSuspendResume();
|
void toggleSuspendResume();
|
||||||
void stateChanged(QAudio::State state);
|
void stateChanged(QAudio::State state);
|
||||||
void deviceChanged(int index);
|
void deviceChanged(int index);
|
||||||
|
void volumeChanged(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user