How to get the default audio device?

扶醉桌前 提交于 2020-01-06 08:14:13

问题


I'm using a 3-rd party DLL which can enumerate the audio devices (providing name and guid-id) and set an audio device to the default one (by the id).

How can I get the current audio device (which is used by OS)? I need either name or device id.

This question seems to have no useful answers.

This one as well.


回答1:


You can use DirectShow for this.

private IBaseFilter CreateFilter(Guid category, string name)
{
    object source = null;
    Guid guid = typeof(IBaseFilter).GUID;
    foreach (DsDevice device in DsDevice.GetDevicesOfCat(category))
    {
        if ( device.Name == name )
        {
            device.Mon.BindToObject(null, null, ref guid, out source);
            break;
        }
    }
    return (IBaseFilter)source;
}
// Get device like this:
IBaseFilter defaultSoundDevice = CreateFilter( FilterCategory.AudioInputDevice, "Default DirectSound Device" );

Update #2:

DsDevice[] audioRenderers;
audioRenderers = DsDevice.GetDevicesOfCat(FilterCategory.AudioInputDevice);
foreach (DsDevice device in audioRenderers)
{
    MessageBox.Show(device.Name);
}


来源:https://stackoverflow.com/questions/21611573/how-to-get-the-default-audio-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!