audio.seek()

Type Function
Library audio.*
Return value Boolean
Revision 2017.3111
Keywords audio, seek, position
See also audio.rewind()

Overview

Seeks to a time position on either an active channel or directly on the audio handle.

This function returns true on success or false if otherwise.

Gotchas

There are subtle behavior differences depending on whether you used audio.loadSound() or audio.loadStream() on what you are trying to seek:

Also note that for files loaded with audio.loadStream() which are currently playing, you may not hear the audio update immediately until after the current buffer finishes playing. If you want seemingly "instantaneous" seeking, you should stop the playback first using audio.stop(), seek, then start playing.

Syntax

audio.seek( time [, audioHandle ] [, options ] )
time (required)

Number. The time in milliseconds within the audio handle you want to seek to.

audioHandle (optional)

Object. The audio handle of the data you want to seek. This should only be used for audio loaded with audio.loadStream(). Do not use the options.channel parameter in the same call.

options (optional)

Table. Table that supports a single key, channel, which is the channel you want the seek operation to apply to. This is best for audio loaded with audio.loadSound(). Do not use the audioHandle parameter in the same call.

Examples

Preloaded Audio
audio.seek( 5000, { channel=1 } )  -- Seek channel 1 to 5 seconds
Streaming Audio
audio.seek( 4000, backgroundMusic )  -- Seek the audio handle to 4 seconds