问题
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