Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if system has sound C#

Tags:

c#

audio

xna

We are currently developing a game using XNA and we've stumbled upon a little sound problem.

When a system has no sound device plugged in (speakers, etc. -- when Win7 shows a red cross on the speaker icon) it crashes when trying to play/load the sound.

So, we would like to check if the system has the capacity of outputting sound. Is it possible in C#?

like image 389
Sirithang Avatar asked Apr 13 '11 13:04

Sirithang


People also ask

How do I know if my computer has a sound card?

Press the Windows key + Pause key. In the window that appears, select Device Manager. Click the Arrow next to Sound, video and game controllers. Your sound card is in the list that appears.

How do I find my sound card settings?

Sound card settings can be found within your PC's control panel, or they are accessible through OTOsuite's Configuration Wizard. To check your sound cards are configured correctly, open Tools > Configuration Wizard select 'Configure' for PMM. Click 'Next' once.


1 Answers

Are you sure that it is actually crashing, and not simply throwing an unhandled exception?

In theory it should throw a NoAudioHardwareException.

Try doing something with audio (SoundEffect.MasterVolume comes to mind as a possibility, as it is a static method) and see if you can catch the exception. If you do catch an exception, simply do no further audio work.

like image 146
Andrew Russell Avatar answered Sep 21 '22 23:09

Andrew Russell