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.

有帮助吗?

解决方案

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top