Question

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.

Était-ce utile?

La solution

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);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top