How to set sound volume programmatically
Hi all,
From time to time I like to post about other issues which are not related to crypto stuff, but I consider useful because of the number of request I get on them. And this is one common question I've seen: how do I set sound volume programmatically on Windows?
On Windows XP we can manipulate audio settings with Wave API or Dsound API (Direct Sound). The following function may help here: waveOutSetVolume. Here is the rest of the API: Waveform Functions. And here we can find a .NET sample which mixes .NET classes and that API: Using P/Invoke to Call Unmanaged APIs from Your Managed Classes. Another sample, this time from a third-party: Mute volume in vb.net program.
On Windows Vista and later that API is no longer available. We may use MMDevice API and EndpointVolume API instead. Here you can see some samples: How do I change the master volume in Windows Vista & Vista Core Audio API Master Volume Control.
I hope this helps.
Regards,
Alex (Alejandro Campos Magencio)
Comments
- Anonymous
February 08, 2011
Hi,I use EndpointVolume API on windows 7Can you help me with some issues related to the EndpointVolume API?When I used Wave API on windows XP, I could control the volume CD in. I put on the same computer, windows 7, and found all audio devices through the EndpointVolume API, but CD in did not find. In the windows 7 system mixer, CDIN also absent.How can I solve this problem?In the system mixer (in microphone properties) is a property of "Listen to this device". How can I programmatically change the property? - Anonymous
April 08, 2014
What to do if we want the opposite of this? (Know when the volume is changed from volume mixer)