tags:

views:

364

answers:

3

I am trying to play the Asterisk system sound from a C# program with

System.Media.SystemSounds.Asterisk.Play();

but no sound plays. My system does have a sound set up for Asterisk and other programs (not written by me) cause various system sounds to play.

Can anyone suggest any possible reasons for this?

+1  A: 

Sorry if this is overstating the obvious...

  1. Are you sure this line of code is being executed?
  2. As RobS suggests do any of the other SystemSounds play?

I had a look in reflector. Whichever of the SystemSounds you call returns a SystemSound instance initialised with the type (e.g. 0x40 for Asterix) for the system sound you want to play. This is then passed to the Win32 bool MessageBeep( int type ) method. Imported as:

[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
internal static extern bool MessageBeep(int type);

The bool return isn't preserved in any way - i.e. you can't get it :(

Exceptions are not swallowed so you should get any if thrown.

Hope that helps (though probably just telling you what you already know)

ng5000
A: 

Is the speaker set on mute? ;)

shahkalpesh
+1  A: 

I had ignored this problem until today. Some googling revealed that this is quite a common problem and totally unrelated to the .NET Play calls.

What happens is that while you can play/preview the sounds from the Control Panel Sounds and Audio Devices applet they do not play when programs trigger the sounds. It seems to be corruption caused by program installations. The fix is quite simple.

The (Default) entry for HKEY_CURRENT_USER in the registry should be (value not set). If it is something else (mine was OfficeCompleted) delete the entry (right click and select delete) and it will be re-created as (value not set). The system sounds should then play.

Steve Crane