How to play a background music and make it loop?

和自甴很熟 提交于 2019-12-08 12:11:32

问题


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:


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



来源:https://stackoverflow.com/questions/8182738/how-to-play-a-background-music-and-make-it-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!