简体   繁体   中英

How to change default audio input device programatically

I am looking for a way to set/change default input device inside my application. I have several different recording devices and it is very anoying to go into the control panel and change default recording device. I was looking around and I did not find anything that could help me with the problem. Application is written in c# and it is targeted for Windows Vista / Windows 7.

This can now (actually for quite some time already) be done very easily using theAudioSwitcher.AudioApi.CoreAudio NuGet package .

Simply create a new CoreAudioController :

var controller = new AudioSwitcher.AudioApi.CoreAudio.CoreAudioController();

Get hold of the desired device using its GUID:

var device = controller.GetDevice(Guid.Parse(...));

And lastly set it as the default playback device:

controller.DefaultPlaybackDevice = device;

Note: this answer was also posted under this question .

There is no public API to do this in Vista/7 AFAIK.

For a media center launch thing I created, I had to open the control panel and send keys to the dialog, a big ugly hack, but it's the best you can do. (Or run .net reflector on media center (It is able to change it, using undocumented calls))

If you had Windows XP, apparently , you can do this by editing the registry. The key HKEY_CURRENT_USER\\Software\\Microsoft\\Multimedia\\Sound Mapper\\Playback contains the name of the current default playback device.

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