简体   繁体   English

启用和禁用播放和记录设备

[英]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.. 我是C#的新手。.如果这个问题有点愚蠢,请不要因为我的问题而烦恼。

I need to see the disabled playback and recording devices by c# code and want to enable or disable it as per my need. 我需要通过c#代码查看已禁用的播放和记录设备,并根据需要启用或禁用它。 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. 我使用DirectX.DirectSound API编写了代码,但是它仅限于枚举仅启用的设备,而我看不到已禁用的设备。 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. 并且还建议我,如果可能的话,如何使用其他API来做到这一点。

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 我意识到这是一个非常古老的线程...但是我登陆这里试图找出如何列出禁用的音频设备,并且我成功完成了一个名为AudioEndpointController的C ++项目

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#. 至于问题的第一部分(需要查看禁用的设备),实际上是可能的,但不能单独使用c#,您必须通过使用C ++ / CLI或在C#中使用显式PInvoke来使用WASAPI。 You're looking for IMMDeviceEnumerator::EnumAudioEndpoints which takes a flag indicating if you want to see disabled/unplugged etc. devices. 您正在寻找IMMDeviceEnumerator :: EnumAudioEndpoints,它带有一个标志,指示您是否要查看已禁用/未插入等设备。 See http://msdn.microsoft.com/en-us/library/windows/desktop/dd371400%28v=vs.85%29.aspx . 请参阅http://msdn.microsoft.com/zh-cn/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. 在这种情况下,关于WASAPI的IMMDevice接口的好处是,它公开了一个与设备的DirectSound ID对应的GUID,因此您实际上可以使用WASAPI来检测哪些设备处于活动状态/不活动状态等,并使用DirectSound进行所有其他操作。 For this, you'll want to use IMMDevice::OpenPropertyStore, and query for the PKEY_AudioEndpoint_GUID property. 为此,您将要使用IMMDevice :: OpenPropertyStore,并查询PKEY_AudioEndpoint_GUID属性。 This is the exact same thing that's passed in to DirectSound's DSEnumCallback function. 这与传递给DirectSound的DSEnumCallback函数完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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