开发者

C# How to programatically change the playback device

开发者 https://www.devze.com 2022-12-08 21:14 出处:网络
How can I programatically change the d开发者_StackOverflowefault audio device on a vista / win 7 system? Using C# or a Win API call?The WinMM API should provide the functionality that you request.

How can I programatically change the d开发者_StackOverflowefault audio device on a vista / win 7 system? Using C# or a Win API call?


The WinMM API should provide the functionality that you request.

You would use the DRVM_MAPPER_PREFERRED_SET message, which is sent with waveOutMessage() function.

Documentation: http://msdn.microsoft.com/en-us/library/aa909789.aspx

However, if you are trying to send the waveform sound out yourself, you should look at the WinMM.Net library.

http://winmm.codeplex.com


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消