Solved

Mute Sound in C# without using DirectX

Posted on 2003-10-27
2
3,277 Views
Last Modified: 2012-08-13
Hi!

I need to code a program which is able to mute the computers audio.
This program should run on xp / nt... i don't exactly know if NT pcs need directX but i know for sure that its not installed...

Is there a way?
0
Comment
Question by:eliaZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 250 total points
ID: 9627653



Here is the WINAPI for the dll you can use if you don't want to go through the hassle of using DIRECTX.

[DllImport("winmm.dll")]
Private static extern long auxSetVolume(long uDeviceID, long dwVolume);

uDeviceID:
The device ID of the auxiliary audio device to set the volume of. Valid values range from zero to the number of auxiliary audio devices minus one.

dwVolume:
The new volume setting of the device. If the device supports separate left and right channel volumes, the low-order word contains the left channel volume and the high-order word contains the right channel volume. If the device supports only one overall volume, the low-order word is the volume. Valid volumes range from 0 to 0xFFFF.



When referencing this as a LONG value, I am pretty sure that they mean this is an Int32 value (which is a standard int primitive type in .NET, where as Int16 is the standard size of the Integer primitive type in most other platforms).  Also something to note is how the volume is controlled.  you may have to do some Hex conversion to get it right.

//sets both the left and right speakers to half volume
retval=auxSetVolume(0,0x80008000);

//sets both the left and right speakers to full volume
retval=auxSetVolume(0,0xFFFFFFFF);

//Mutes both the left and right speakers
retval=auxSetVolume(0,0);

0
 
LVL 22

Assisted Solution

by:_TAD_
_TAD_ earned 250 total points
ID: 9627678


The downside to using WINAPI is that it actually affects the OS.  If you want to be nice, you will first get the sound settings and store them in a variable somwhere.  Mute the sound, and then when your program shuts down set the sound level to the place where it was before.

But that's just my opinion.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question