How to play a background music and make it loop?

2019-09-02 15:11发布

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);

1条回答
Animai°情兽
2楼-- · 2019-09-02 16:01

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

查看更多
登录 后发表回答