F34R
F34R

Reputation: 127

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.

Upvotes: 2

Views: 4856

Answers (4)

Saber
Saber

Reputation: 11

Today, on. net 8's WPF, AudioSwitch AudioApi CoreAudio can no longer work, and I have found another answer. The author's method can be easily solved Use "CoreAudio" Modifying audio playback devices

Upvotes: 0

kwyntes
kwyntes

Reputation: 1302

This can now (actually for quite some time already) be done very easily using the AudioSwitcher.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.

Upvotes: 4

svick
svick

Reputation: 244998

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.

Upvotes: 0

Anders
Anders

Reputation: 101756

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))

Upvotes: 1

Related Questions