We already know how to play audio files, but it is also important to know how to stop them from playing. This is particularly important for looping sounds, because otherwise they would keep repeating forever. Usually, all we have to do is call the stop()
method on the channel handle:
channel->stop();
When a sound stops playing—because it reached the end and it is not set to loop, or because we stopped it ourselves—its channel becomes free for other sounds to use. This means that once we stop a sound there is no way to resume it. If we need to stop a sound temporarily, and resume it at a later time, we need to use the setPaused()
method:
// Pause the sound channel->setPaused(true); // Resume the sound channel->setPaused(false);
Most methods that start with set
are accompanied by an equivalent get
method, such as getPaused()
, that we can use to check the current value of that property. The following is a function that uses both methods in conjunction with each...