Type Function
Library audio.*
Return value Number
Revision 2017.3077
Keywords audio, stop, delayed stop, stop with delay
See also


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 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 So for audio.loadStream(), you may want to call audio.rewind() on the handle if you reuse the audio handle.


audio.stopWithDelay( duration [, options ] )
duration (required)

Number. Time in milliseconds after which to stop playing.

options (optional)

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 = backgroundMusic, { loops=-1 }  ) 
audio.stopWithDelay( 30000, { channel=backgroundMusicChannel }  )