Stopping Sounds, Resuming Sounds

0
99

Stopping Sounds

To stop a sound from playing, simply call the stop function on its channel:

channel.stop();

To stop streaming audio, calling the stop function works once, but the sound starts playing again from the beginning. This is because the stream is still downloading. You also need to stop the downloading process:

channel.stop();
sound.close();

If you have several sounds playing at the same time, you can stop the sounds of all the channels one at a time.

The best approach is to use the static SoundMixer class, which controls embedded and dynamic sounds and the mixed output from multiple sound channels. You can use this class to stop as well as control the volume of all the sounds currently playing:

SoundMixer.stopAll();

Resuming Sounds

There is no direct way to pause a sound and then resume playing, but you can easily create the same effect by storing the position of the channel where you stop, and start from that same position when playing again:

var lastPosition:int = channel.position;
channel.stop();
// to resume from the same position
sound.play(lastPosition);