2

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.

Gordon Bell
  • 13,337
  • 3
  • 45
  • 64
F34R
  • 128
  • 2
  • 5

3 Answers3

3

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.

kwyntes
  • 1,045
  • 10
  • 27
  • 1
    I don't really need this anymore but since you provided an answer after 13 years you do need a thumbs up. I also tried the package and it works as expected. – F34R Nov 03 '22 at 10:11
  • I tried that in my app. The very first line var controller = new AudioSwitcher.AudioApi.CoreAudio.CoreAudioController(); goes in and start throwing exceptions inside of it and ruturns a minute later but exceptions keep displaying: Exception thrown: 'System.NullReferenceException' in AudioSwitcher.AudioApi.CoreAudio.dll – Leon Dec 04 '22 at 00:52
1

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

Anders
  • 97,548
  • 12
  • 110
  • 164
  • Opening control panel is not an option and I dont need it for media center, but tnx for suggestion. – F34R Sep 02 '09 at 10:12
  • Opening the control panel and automating the dialog is your only legal option – Anders Sep 02 '09 at 13:29
  • 1
    @Matthias Vance http://blogs.msdn.com/larryosterman/archive/2008/07/11/whatever-happened-to-wave-out-mix.aspx#8769290 see the last comment by Larry – Anders May 17 '10 at 09:06
  • You are right, I was confused by the answer giving in the other SO thread (user replying that it would work on Windows 7). –  May 18 '10 at 12:06
0

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.

svick
  • 236,525
  • 50
  • 385
  • 514