How to stop all sound in a C# program

This is a discussion on How to stop all sound in a C# program within the C# Programming forums, part of the General Programming Boards category; Hi all, Now I am programing a game in C#. So I use many sound events (moving, punching, screaming...). I ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    11

    How to stop all sound in a C# program

    Hi all,
    Now I am programing a game in C#. So I use many sound events (moving, punching, screaming...). I create a Mute button, when running program. when users click on Mute, all sound will be disabled. So, i want use a system call from thread library, some thing like that...I have searched in MSDN but no feasible result. Somebody answer me, please. Many thanks!

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    They way I had implemented it is to use a bool variable for all sounds and check that before you play the sound. The Mute button will just set that variable.

    If you want to be more elegant and maybe save re-writing code and stuff, you can create your own Play() method and put the actual method that plays the sound in there. Then give it parameters and make it check internally for the "muteAll" bool variable. Then simply do a Find-Replace to replace all previous play methods accordingly and you are done.

    You can use other methods if you want to actually mute the volume. You can use DirectX for that matter. I have some code for that (unfortunately wasted) that I can give you here if that is the solution you want. Of course it is more complicated than what I mentioned above and less efficient since why play the sound if nobody will hear it?

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    11
    Quote Originally Posted by C_ntua View Post
    They way I had implemented it is to use a bool variable for all sounds and check that before you play the sound. The Mute button will just set that variable.

    If you want to be more elegant and maybe save re-writing code and stuff, you can create your own Play() method and put the actual method that plays the sound in there. Then give it parameters and make it check internally for the "muteAll" bool variable. Then simply do a Find-Replace to replace all previous play methods accordingly and you are done.

    You can use other methods if you want to actually mute the volume. You can use DirectX for that matter. I have some code for that (unfortunately wasted) that I can give you here if that is the solution you want. Of course it is more complicated than what I mentioned above and less efficient since why play the sound if nobody will hear it?
    Thanks you. I have used a bool variable to control my sound function, so I want a function that can be used in many cases. I hoped thread supported that.

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    By google searching I found this

    There are ways to mute the system volume if that is what you want.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cant stop program & some errors
    By nitediver in forum C Programming
    Replies: 17
    Last Post: 10-02-2009, 02:35 AM
  2. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 03:58 PM
  3. continuing program until ready to stop
    By jlmac2001 in forum C++ Programming
    Replies: 2
    Last Post: 01-19-2003, 07:19 PM
  4. sounds?
    By BODYBUILDNERD in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2002, 03:34 PM
  5. anyone know how to upload long sound files into a program?
    By Golden Bunny in forum C++ Programming
    Replies: 18
    Last Post: 04-11-2002, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21