Steve Crane
Steve Crane

Reputation: 4440

SystemSounds Play not working

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?

Upvotes: 5

Views: 4383

Answers (3)

teynon
teynon

Reputation: 8328

I'm only 8 years late to the party, but I just had this issue on a Windows 7 tablet PC. The thing that fixed it? The classic Restart.

Try restarting the device.

Upvotes: 1

Steve Crane
Steve Crane

Reputation: 4440

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.

Upvotes: 5

ng5000
ng5000

Reputation: 12590

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)

Upvotes: 1

Related Questions