I've learned that XAudio device creation fails if there are no speakers plugged into the PC. That is weird... it is like DirectX failing to initialized because there is no monitor plugged in.
Not sure if the OpenAL path suffers from this as well.
MonoGame should be able to internalize this and keep it from being an issue the game developer has to deal with.
Reading 4715; this issue replicates what XNA does but we want it better?
Is this at runtime when a game starts, in either XNA or MonoGame will crash if it can't find hardware to create an audio device from?
If we changed this behavior then all the existing code that relies on XNA throwing an exception wouldn't work the same ;-)
I have this error happening out of the Microsoft.Xna.Framework.Game constructor when I call base(), so I'm trying to figure out how to even add code that relies on this exception. If it is throwing an exception in the base constructor every time, how would you rely on that exception in a way that isn't horrible for the user? How do you spin up anything useful for the user without an audio device connected? Do you just try-catch around the game constructor and show an alert before ultimately exiting to desktop?
Odd place for an exception like this, and not how XNA does things;. XNA will throw a NoAudioHardwareException only when you actually try to use the audio subsystem, either by initializing the XACT classes or by attempting to play audio using the SoundEffect or Song classes. As long as you don't do that, you _should_ be safe.
I think that the MonoGame code should be changed to lazily initialize the audio subsystem when first used.
Even if the audio system was lazily initialized, it doesn't seem like the game should necessarily have to care about there not being audio hardware. Even if a game tries to play audio on a system with no way to do so, it should just carry on like it worked (potentially offering a way to detect the no-hardware situation for user-facing troubleshooting messaging). It feels like there shouldn't really be a NoAudioHardwareException as much as a HasAudioHardware property somewhere.
@patridge
Even if a game tries to play audio on a system with no way to do so, it should just carry on like it worked (potentially offering a way to detect the no-hardware situation for user-facing troubleshooting messaging).
That's what the exception is for ;)
You catch it, set a flag to not use audio from that point forward, and you're good.
It feels like there shouldn't really be a NoAudioHardwareException as much as a HasAudioHardware property somewhere.
True, but that's the way XNA does it. And probably the way MonoGame should do, too, as long as they're trying to emulate XNA.
There is now a mechanism to detect this and proceed without sound if need be: #6629
Most helpful comment
Odd place for an exception like this, and not how XNA does things;. XNA will throw a NoAudioHardwareException only when you actually try to use the audio subsystem, either by initializing the XACT classes or by attempting to play audio using the SoundEffect or Song classes. As long as you don't do that, you _should_ be safe.
I think that the MonoGame code should be changed to lazily initialize the audio subsystem when first used.