Sound effect stopped working

May 12, 2010 at 2:52 PM
I used the sound effect class to create sound for hovering buttons:

SoundEffect se = new SoundEffect(Game1.contentManager, "Sound/hammer-1");
se.Play(1.0f, 1.0f, 1.0f, false);

I hovered the buttons and the sound played as expected, but after a while it stopped playing the sound effect. What could be the problem here? I used breakpoints to see if it still reached the code and it did and everything seemed to be fine so I havent got a clue what it could be.
I used an mp3-file as effect if that could be any help.

And when I am on the sound problem.. Should I play music with the soundeffect class or should I use something else for this? Tried the MediaPlayer as in XNA but it failed and gave me an NotImplemented-exception.
Coordinator
May 12, 2010 at 11:06 PM

Yeah there are some issues with sound in general, especially with really short sounds. You may want to try playing a WAV file instead and see if that helps.

May 13, 2010 at 8:15 AM

ok! I tried to play a wav-file but it didn't play the sound and the conversion guide said only mp3 and wma so I guessed it was because it wasn't supported.

Coordinator
May 13, 2010 at 11:17 AM
WAV is only supported in the latest source code, not in the downloads, not sure which you tried.
May 14, 2010 at 10:10 AM

Ok! I used the download so thats the reason.

May 18, 2010 at 10:38 AM

I am using the latest source of Silversprite and I've been fighting with audio for a long time now. I've finally got to the point where most of the problem is eliminated, but I'd like a more solid solution.

Problem: During first 5-6 seconds of ACTUALLY playing sound effects (which are short, 1-2 second clips), the file does not start playing from the beginning. It always starts playing around the middle of the sound. This happens on ALL file types (wav, mp3, and wma). I even reset the "Position" property of the media element, increase the "BufferingTime", AND check "BufferingProgress" to make sure the sound is loaded. Yet for the first 5-6 seconds of gameplay, the file REFUSES to consistantly play from the beginning.

I've been surfing microsoft forums as well for an answer to this issue, yet I still haven't found an anwser. So if anyone has information about how to properly load and play sound effects, that would be an enormous help. And I would bake you cookies :D

May 20, 2010 at 7:51 AM

Okay I will end this post for now. I am currently using Windows XP, the Silverlight 4 and the latest silversprite SOURCE. The audio problem is corrected for 95%, by using an AudioManager class to control silversprite's native song and sound effects classes. In my earlier post, this only creates the soundeffects to lag for about 5-6 seconds before working normally throughout the entire lifetime of the application.

Now if I switch to a faster machine, using Windows 7, there are NO AUDIO problems or lag at all. I tested this all afternoon, so I'm starting to assume that the final 5% of problems I was having was my machine itself. Guess I'll have to put my friendly XP system to sleep soon and upgrade like the rest of the world....the time has come!

May 21, 2010 at 3:59 PM
Edited May 21, 2010 at 8:02 PM
Might as well add it on here, is there a way to stop the sound playing? I have looked and can't find a way to achieve this, cheers. Edit: I coded this, not sure its the best way though. public void Stop() { try { foreach (SoundEffectInstance sound in sounds) sound.Stop(); } catch(Exception ex) { } }
May 28, 2010 at 8:25 AM

I used the soundeffect class too and it doesn't work all that bad for me. At some computers the sound lags a bit at the start of the game. On these computers it sometimes hangs the game, but only for short and never again (at least that's what I found). On others it works without any hick-up. I did however insert a short silence at the start of every sound. So yes, the sound is somewhat delayed, but it gets played completely in most cases.

I also had troubles stopping a sound. My solution was to use SoundEffect.CreateInstance(), store the received instance, and then, when you want to stop the sound, set the instance to null and order for garbage collection, GC.Collect(). This was only to stop the music if the player wanted to, so I don't know what the performance hit will be if you do this often during the game.

Jun 9, 2010 at 2:34 PM

Well NOW i've into another sound issue....on the MAC.

I recently uploaded my silversprite game onto the internet and some of my beta testers say that on the mac, the volumes of the soundeffects vary between getting loud and quiet, and sometimes just STAYING quiet all together and the sound never comes back.

Is there a common bug where you can't load a lot of sound effects in the same class, or you run out of sound buffers, or perhaps the soundeffect instances are being called/destroyed wrong??

I am really at my wits end on this problem. I KNOW you other game developers out there use sound effects in your games! Anyone have suggestions?

Thanks so much in advance!!!