Type Function Library audio.* Return value Number Revision Release 2022.3683 Keywords audio, stop, delayed stop, stop with delay See also audio.play() audio.stop()
Stops a currently playing sound after the specified time delay.
This function returns the number of channels actually applied to or -1
on error.
Note that audio.stopWithDelay()
does not take any handles from audio.loadSound() or audio.loadStream(). This is by design, since you are intended to stop specific channels, not sound handles.
For audio loaded with audio.loadStream(), the position of the audio will not be reset when stop is called. So when if you call audio.play() again on the same handle, it will continue approximately where it left off (it might be a little further down because all of the pre-filled buffers were discarded on the audio.stop()). This contrasts with audio loaded with audio.loadSound() which will start playing at the beginning of the starting position of the buffer (beginning of the sound unless you modified it with audio.seek()). So for audio.loadStream(), you may want to call audio.rewind() on the handle if you reuse the audio handle.
audio.stopWithDelay( duration [, options ] )
Number. Time in milliseconds after which to stop playing.
Table. Table that supports a single key, channel
, which is the channel to stop. If no parameter is passed, all channels are stopped.
local backgroundMusicChannel = audio.play( backgroundMusic, { loops=-1 } ) audio.stopWithDelay( 30000, { channel=backgroundMusicChannel } )