Zainu
Zainu

Reputation: 912

How to play a background music and make it loop?

How to play a background music and make it loop?

Currently I'm using this piece of code to make it play the background music:

XNA-C#

SoundEffect bgEffect;
bgEffect = Content.Load<SoundEffect>("EpicUnease");
bgEffect.Play(0.1f, 0.0f, 0.0f);

Upvotes: 1

Views: 28131

Answers (1)

H Bellamy
H Bellamy

Reputation: 22725

If this is not XNA, you can reference System.Media and do this:

SoundPlayer sound = new SoundPlayer("path");`
sound.PlayLooping();

For XNA you would do something like this:

SoundEffect bgEffect;
bgEffect = Content.Load<SoundEffect>("EpicUnease");
SoundEffectInstance instance = bgEffect .CreateInstance();
instance.IsLooped = true;
bgEffect.Play(0.1f, 0.0f, 0.0f);

For more information, check out this msdn article: http://msdn.microsoft.com/en-us/library/dd940203.aspx

Upvotes: 11

Related Questions