❝可设置/同步扬声器与录音音量。(目前仅支持Windows系统)❞
VolumeController
对外接口。class VolumeController
{public:
explicit VolumeController();
virtual ~VolumeController();
int getSpeakerVolume();
bool setSpeakerVolume(int volumePercent);
bool isSpeakerMuted();
bool setSpeakerMuted(bool mute);
int getMicVolume();
bool setMicVolume(int volumePercent);
bool isMicMuted();
bool setMicMuted(bool mute);
private:
IAudioEndpointVolume* getEndpointVolume(bool isSpeaker);
private:
IAudioEndpointVolume *m_speakerEndpointVolume;
IAudioEndpointVolume *m_micEndpointVolume;
};
onUpdate()
,并设置更新时间为500ms。connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(onUpdate()));
m_updateTimer.start(500);
onUpdate()
槽函数实现。void onUpdate()
{
int micVolume = m_volumeController->getMicVolume();
int speakerVolume = m_volumeController->getSpeakerVolume();
ui->horizontalSlider->setValue(micVolume);
ui->horizontalSlider_2->setValue(speakerVolume);
ui->label_2->setText(QString::fromLocal8Bit("录音音量:(%1%)").arg(micVolume));
ui->label_3->setText(QString::fromLocal8Bit("扬声器音量:(%1%)").arg(speakerVolume));
}
void on_horizontalSlider_valueChanged(int value)
{
qDebug() << "Set mic volume: " << value
<< "; Result: " << m_volumeController->setMicVolume(value);
}
void on_horizontalSlider_2_valueChanged(int value)
{
qDebug() << "Set speaker voluem: " << value
<< "; Result: " << m_volumeController->setSpeakerVolume(value);
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有