Solved

Mute Sound in C# without using DirectX

Posted on 2003-10-27
2
3,237 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now