views:

43

answers:

0

Hi!

I am trying to implement a simple game in .NET with C#. There is a ball bouncing against objects, and when it bounces I play a sound asynchronously using System.Media:SoundPlayer. The problem is that most of the time (not always) the ball freezes at the time of impact, for as long as the sound plays.

This happens on Windows XP, but not on Windows 7. I use .NET 3.5. And the weirdest thing is that the problem disappears if I open the application Windows Media Player and play a few seconds of an mp3.

Here's the code where I initialize the SoundPlayer object:

System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream s = a.GetManifestResourceStream("Game.Resources.GameBounce.wav");
_playerBounce = new System.Media.SoundPlayer(s);
_playerBounce.Load();

...and when the ball hits an obstacle, this line is called: _playerBounce.Play();

I have also tried "Attempt #4" in this post: http://stackoverflow.com/questions/1161229/how-to-use-system-media-soundplayer-to-asynchronously-play-a-sound-file

Another desperate attempt, based on some advice I found somewhere on the net, was to save the sound stream to a file, that SoundPlayer works better when initialized from a file.

Neither of those attempts worked.

Any ideas?