Hi Kamal, SoundEffect.Play has an overload that allows you to loop a sound.
Here's some basic sample code that should do what you want (of course, sfx and sfxi are SoundEffect and SoundEffectInstance types that you'll need to define in your game).
| if (Keyboard.GetState().IsKeyDown(Keys.Space)) |
| { |
| if (sfxi == null) |
| { |
| sfxi = sfx.Play(1.0f, 0, 0, true); |
| } |
| else |
| { |
| sfxi.Play(); |
| } |
| } |
| else if (Keyboard.GetState().IsKeyUp(Keys.Space)) |
| { |
| if (sfxi != null) |
| { |
| sfxi.Stop(true); |
| } |
| } |