13.15. Fading Out a Sound
You want to fade out a sound over a span of a number of milliseconds.
As with fading in a sound, there is no built-in functionality for
fading out a sound. However, you can create a custom
fadeOut( ) method to handle this task. Our
fadeOut( ) method is slightly longer than
fadeIn( ) method, but it utilizes similar
logic. In addition, the
fadeOut( ) method allows
you to use two callback functions: one that is called when the sound
begins to fade out, and another that is called when the fade out has
completed. This can be useful in situations in which you want a
particular action or actions to occur when the fade out begins and/or
ends. For example, you may want to begin the playback of a second
sound when the first begins to fade out. As the second sound fades
in, you achieve a cross-fade effect.
As with the
fadeIn( ) method, the
fadeOut( ) method works only with sounds that
are created using our custom
fadeOut( ) method accepts up to five
The number of milliseconds over which the sound should fade out.
The volume percentage to which the sound should fade (default is 0).
The volume percentage from which the sound should start fading (default is current volume).
The point (in milliseconds) in the sound that the fade out should begin. If no value is specified, the fade out begins
millismilliseconds before the end ...