Qt获取音频设备信息

Qt中的QAudioDeviceInfo::availableDevices接口可以轻松的获取到音频设备信息

	//获取输入音频设备名称
    QVector aDeviceListI;
    QList audioDeviceListI = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
    foreach (QAudioDeviceInfo devInfo, audioDeviceListI)
    {
        QString strName = devInfo.deviceName();
        if (devInfo.isNull()) continue;
        if (strName[0] == 65533) continue;
        bool bFound = false;
        foreach (QString dev, aDeviceListI) {
            if (strName == dev){
                bFound = true;
            }
        }
        if (bFound == true) continue;
        aDeviceListI.push_back(strName);
        ui->comboBoxInput->addItem(strName);
    }

	//获取输出音频设备名称
    QVector aDeviceListO;
    QList audioDeviceListO = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
    foreach (QAudioDeviceInfo devInfo, audioDeviceListO)
    {
        QString strName = devInfo.deviceName();
        if (devInfo.isNull()) continue;
        if (strName[0] == 65533) continue;
        bool bFound = false;
        foreach (QString dev, aDeviceListO) {
            if (strName == dev){
                bFound = true;
            }
        }
        if (bFound == true) continue;
        aDeviceListO.push_back(strName);
        ui->comboBoxOutput->addItem(strName);
    }

需要完整代码请访问 QtOtherExamples

联系方式:


作者 郑天佐
QQ 278969898
主页 http://www.camelstudio.cn/
邮箱 [email protected]
博客 http://blog.csdn.net/zhengtianzuo06/
github https://github.com/zhengtianzuo
QQ群 199672080

捐赠

weixin.jpg?raw=truezhifubao.jpg?raw=true

觉得分享的内容还不错, 就请作者喝杯咖啡吧~~

你可能感兴趣的:(界面开发)