Answered by:
Looping a sound in C # not working at all.what's wrong with my code

Question
-
may i have a clue pls for my question, i added a sound *.wav file in a small C# coded game, and entered this C# code:>>
SoundEffect sound;
sound = Content.Load<SoundEffect>("bonus_music");
sound.Play();
SoundEffectInstance instance = sound.CreateInstance();
instance.IsLooped = true; ( help guide with sample on msdn >> looping a sound in C#).My *.wav file called "bonus_music" play till the ends but it is not looping,that is is not repeated.i add it in>>> SolutionExplorer>> Content like add>>existing item >> and selecting my *.wav file.i have no errors while compiling ,but that sound is not repeated continually, it plays only 1 time then stops.
what am i doing wrong? any suggest? tvm .Enrico /Italy
Ps: i am a newbie in C# and trying to learn some:)
I am using Visual C# 2010 Express edition and XNA Game Studio 4.0.
Monday, December 24, 2012 2:59 PM
Answers
-
Hi,
Set the IsLooped property to true and call the SoundEffectInstance.Play Method.
Please refer the following sentence under Remarks section in this link.
To loop a sound or apply 3D effects, call CreateInstance instead of Play, and SoundEffectInstance.Play.
- Edited by Ramesh Swaminathan Monday, December 24, 2012 3:35 PM
- Proposed as answer by Bob Shen Tuesday, December 25, 2012 7:00 AM
- Marked as answer by Just Karl Wednesday, November 13, 2013 4:51 PM
Monday, December 24, 2012 3:26 PM -
Hi e21959,
For XNA, please use below more appropriate forum:
http://xboxforums.create.msdn.com/forums/default.aspx?GroupID=6
Thanks.
Bob Shen
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Just Karl Wednesday, November 13, 2013 4:51 PM
Wednesday, December 26, 2012 3:36 AM
All replies
-
Hi,
Set the IsLooped property to true and call the SoundEffectInstance.Play Method.
Please refer the following sentence under Remarks section in this link.
To loop a sound or apply 3D effects, call CreateInstance instead of Play, and SoundEffectInstance.Play.
- Edited by Ramesh Swaminathan Monday, December 24, 2012 3:35 PM
- Proposed as answer by Bob Shen Tuesday, December 25, 2012 7:00 AM
- Marked as answer by Just Karl Wednesday, November 13, 2013 4:51 PM
Monday, December 24, 2012 3:26 PM -
Hi. Tvm for reply. seems like following your suggest the right code the exactcodeshould look like this:
SoundEffect soundEffect;
soundEffect = Content.Load<SoundEffect>("music_wav");
SoundEffectInstance instance = soundEffect.CreateInstance();
instance.IsLooped = true;
instance.Play();but, this is not working too,after starting debug, music_wav play for 1/10 sec about (for a very short time) then stops immediately leaving game with no sound.i am stuck at this point.
i' ve solved using XNA *.xap Project and with another classfrom Xna.framework :
System.Media.SoundPlayer Player1 = new System.Media.SoundPlayer("bonus_music.wav");
Player1.Play();
Player1.PlayLooping();both are working fine. remain my interest to use SoundEffectInstance class to have a sound working loop , not yet solved. Tvm :) i stay tuned shuold you have other suggest.
Enrico /italy
Tuesday, December 25, 2012 11:34 AM -
Hi e21959,
For XNA, please use below more appropriate forum:
http://xboxforums.create.msdn.com/forums/default.aspx?GroupID=6
Thanks.
Bob Shen
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Just Karl Wednesday, November 13, 2013 4:51 PM
Wednesday, December 26, 2012 3:36 AM -
i 'll pay more attention :) sry was not intentional :) tx for suggest:)
Enrico /Italy
Sunday, March 3, 2013 6:19 PM