简体   繁体   中英

Enabling and disabling playback and recording devices

I am a newbie in c#..Please dont get annoyed by my question if its kinda silly one..

I need to see the disabled playback and recording devices by c# code and want to enable or disable it as per my need. How can I approach..?? I made a code using DirectX.DirectSound API but it is limited to enumerate the devices which are only enabled and i am not able see the disabled devices present. And I don't think there is any method of disabling or enabling the devices.

I'll be very thankful to u for the help.

And please also suggest me how can I do this with using other API's if possible.

I realize this is a really really old thread... but I landed here trying to find out how to list disabled audio devices, and I was successful with a C++ project called AudioEndpointController

Simply change the line:

PlaybackDevice = pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pDevices);

to:

PlaybackDevice = pEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_DISABLED, &pDevices);

As far as i know, it is not possible to programatically enable/disable devices. As for the first part of your question (need to see disabled devices), this is in fact possible but not using c# alone, you'll have to use WASAPI for this either by using C++/CLI or using explicit PInvoke in C#. You're looking for IMMDeviceEnumerator::EnumAudioEndpoints which takes a flag indicating if you want to see disabled/unplugged etc. devices. See http://msdn.microsoft.com/en-us/library/windows/desktop/dd371400%28v=vs.85%29.aspx . The nice about WASAPI's IMMDevice interface in this case is that it exposes a GUID which corresponds to the device's DirectSound id, so you can actually use WASAPI to detect which devices are active/inactive etc. and do all your other stuff using DirectSound. For this, you'll want to use IMMDevice::OpenPropertyStore, and query for the PKEY_AudioEndpoint_GUID property. This is the exact same thing that's passed in to DirectSound's DSEnumCallback function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM