Looping a Sound

This section demonstrates how to loop a sound.

Complete Sample

The code in this topic shows you the technique for looping a sound. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.

Simple Sound Looping

Not much extra code is needed to continiously loop a sound file in your game. Since the SoundEffect class does not provide looping support, you'll need to allocate a SoundEffectInstance object. The following procedure builds on the sample code provided in the Playing a Sound topic.

To loop a sound

  1. Follow the instructions show in Playing a Sound topic.

  2. To be able to loop a sound you will need to declare a SoundEffectInstance object, and set it to the return value of SoundEffect.CreateInstance.

    SoundEffectInstance instance = soundEffect.CreateInstance();
  3. Set SoundEffectInstance.IsLooped to true and then play the sound.

    instance.IsLooped = true;


Playing a Sound
Demonstrates how to play a simple sound by using SoundEffect.


SoundEffect Class
Provides a loaded sound resource.
SoundEffectInstance Class
Provides a single playing, paused, or stopped instance of a SoundEffect sound.

Community Additions