Qt获取音频设备信息

//获取输入音频设备名称
    QVector<QString> aDeviceListI;
    QList<QAudioDeviceInfo> 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<QString> aDeviceListO;
    QList<QAudioDeviceInfo> 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);
    }

原文链接:https://zhuanlan.zhihu.com/p/64429934

posted @ 2023-01-03 10:47  远方是什么样子  阅读(152)  评论(0编辑  收藏  举报