0

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.

Community
  • 1
  • 1
AgentFire
  • 8,944
  • 8
  • 43
  • 90

1 Answers1

2

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);
}
Mustafa Chelik
  • 2,113
  • 2
  • 17
  • 29
  • Explain please how should this be used. – AgentFire Feb 07 '14 at 06:58
  • You should download DirectShow.NET library (http://bit.ly/1fPJbjD). It's .NET wrapper of Microsoft DirectShow. You should add DirectShow.NET reference to your project references and use my code. You can find and download DirectShow.NET examples from the link. If you wonder what DirectShow is: http://bit.ly/MykX2g. You can record/play/convert and a lot of things using DirectShow functions. Good luck ;) – Mustafa Chelik Feb 07 '14 at 20:34
  • I have tried this, but your `IBaseFilter` does not provide neither GUID nor a NAME for the actual audio device used by the OS. – AgentFire Feb 07 '14 at 21:37
  • It finds the "Default DirectSound Device" and its DisplayName is "Default DirectSound Device". I need an actual device name, like "Speakers (HD Audio)". – AgentFire Feb 07 '14 at 21:39
  • I have put the code in and how it simply iterates over all my audio renderers (I have replaced `AudioInputDevice` with `AudioRendererCategory`) but there is still no information about which one is the default currently. – AgentFire Feb 08 '14 at 08:33
  • NOW THE first one is the current one, thank you, that worked! – AgentFire Feb 08 '14 at 08:33
  • Oh! My bad. You should get AudioRendererCategory filters not AudioInputDevice. Anyway, you got your answer :) – Mustafa Chelik Feb 08 '14 at 15:20