简体   繁体   English

循环播放声音不适用于C#

[英]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. 我添加了一段代码,在我的Visual C#2010快速版项目游戏中循环* wav文件(我已经在内容文件夹项目中添加了wav文件以及调试文件夹中),但它只播放了一次,直到结束然后它停止。 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#). 即时通讯使用XNA Game Studio 4.0(完全没有问题来循环声音,它工作得很好),但我希望循环声音而不使用XNA,我在MSDN参考和库上跟踪样本,甚至在这个论坛中循环声音C#)。

what am i doing wrong ? 我究竟做错了什么 ? any suggest ? 任何建议? i thought that code was OK. 我认为代码还可以。

You're currently playing the SoundEffect (which isn't looped) rather than the SoundEffectInstance (which is). 您当前正在播放SoundEffect (不是循环播放)而不是SoundEffectInstance (即)。 Try changing the final line to 尝试将最后一行更改为

instance.Play();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM