Qt獲取音訊裝置資訊
阿新 • • 發佈:2019-02-19
Qt中的QAudioDeviceInfo::availableDevices介面可以輕鬆的獲取到音訊裝置資訊
//獲取輸入音訊裝置名稱
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);
}