How to load SoundEffect?

Apr 28, 2010 at 8:07 AM

Hi, I'm making a game with the FlatSilverBall engine. I've got everything worked out, except for the audio. Normally in FlatRedBall I would use Xact audio, but I can't obviously in FSB.

So I start digging and found the SoundEffect class. That meets my needs, but I seem to be unable to load any soundfiles. I guess I'm just doing things wrong. 

I have a .wav file added to the project and set it's build property to 'Content'. I load the effect like this:

[code]            Microsoft.Xna.Framework.Content.ContentManager myXNAContentManager = new Microsoft.Xna.Framework.Content.ContentManager(FlatRedBallServices.Game.Services);
            Microsoft.Xna.Framework.Audio.SoundEffect mySoundLaser = myXNAContentManager.Load<SoundEffect>(@"Content\Sound\sndLaser");
[/code]

There is no exception thrown and I'm sure the file is found (otherwise it will throw an exception), but when I play the sound (mySoundLaser.Play()) I hear nothing and when I investigate it's properties (like duration) they've all thrown exceptions.
I'm sure the file doesn't get loaded properly. But how do I fix this?

Coordinator
Apr 28, 2010 at 12:45 PM

try removing "Content\" from the front of the path and see if that helps. Also WAV files are only supported in the latest source (not in a release yet), and it's experiemental support and there may be issues with it. You can try MP3 or WMA files also. SoundEffects in general are problematic because of underlying problems in Silverlight with playing short overlapped sounds and in the future I'll be looking into ways to improve this but it's not easy.

Apr 28, 2010 at 1:39 PM
Edited Apr 28, 2010 at 1:48 PM

Hi Bill, thanks for your reply.

When I remove the "Content\" part, it says it can't find the file. I have converted the sound to a WMA file (which works), but still the sound won't play and it's proprties are empty. Has it something to do with the way I set up the ContentManager? I must admit I don't use it often, because the FlatRedBall engine takes care of it mostly.

I read in the other topic it has problems, but still I'd like to give it a try and see how far I can get. The games on your site have sound too, right, just like Dr. Popper, which seems to work ok? Or did you had a lot of work on that part?

EDIT: The sound now works! It was the WMA conversion. I also understand now what you mean with problamatic.