检查系统具有完善的C# [英] Check if system has sound C#

查看:122
本文介绍了检查系统具有完善的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用XNA目前正在开发一个游戏,我们已经在一点点声音的问题绊倒了。

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

当系统中有插入声音设备(音箱等 -​​ 当Win7的显示上的扬声器图标红叉)崩溃试图播放/加载声音时

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.

因此​​,我们想检查系统具有输出声音的能力。是否有可能在C#?

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

推荐答案

您确定它实际上是崩溃,而不是简单地抛出一个未处理的异常?

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

在理论上它应该抛出一个 NoAudioHardwareException

In theory it should throw a NoAudioHardwareException.

尝试做音频的东西( SoundEffect.MasterVolume 想到作为一种可能性,因为它是一个静态方法),看看你是否能捕获该异常。如果你这样做捕获异常,根本就没有进一步的音频工作。

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.

这篇关于检查系统具有完善的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆