Enrico Griggio
Enrico Griggio

Reputation: 11

Looping a sound is not working in C#

i have added a piece of code to have a *wav file looped in my Visual C# 2010 express edition Project game (i ve added wav file in content folder project as well in debug folder) , but it plays only 1 time till end then it stops. the code i ve added is these :

 SoundEffect sound;
 sound = Content.Load<SoundEffect>("bonus_music"); 
 SoundEffectInstance instance = sound.CreateInstance();
 instance.IsLooped = true;
 sound.Play();

it is not looping that sound. im using XNA Game Studio 4.0 (with this no problem at all to loop sound, it works perfectly), but i want loop that sound without using XNA , and i followed sample on MSDN reference and library and even in this forum for looping sound in C#).

what am i doing wrong ? any suggest ? i thought that code was OK.

Upvotes: 1

Views: 278

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500595

You're currently playing the SoundEffect (which isn't looped) rather than the SoundEffectInstance (which is). Try changing the final line to

instance.Play();

Upvotes: 3

Related Questions