CoronaApril 26th, 2012shinu.s
Use ‘audio.rewind()’, it rewinds audio to the beginning position on either an active channel or directly on the audio handle.
Syntax:
audio.rewind( [, audioHandle ] [, { channel=c } ] )
Example:
audio.rewind() -- rewind all channels
audio.rewind( backgroundMusic ) -- rewind the audio handle
audio.rewind( { channel=1 } ) -- rewind channel 1
Parameters:
audioHandle
object: The audioHandle of the data you want to rewind. Best for audio loaded with audio.loadStream(). Don’t try using with the channel parameter in the same call.
channel
integer: The channel you want the rewind operation to apply to. Best for audio loaded with audio.loadSound(). Don’t try using with the audioHandle parameter in the same call.
Returns:
True on success or false
Remarks:
There are subtle behavior differences depending on whether you used audio.loadSound() or audio.loadStream() on what you are trying to rewind.
Audio loaded with audio.loadSound() may only seek using the channel parameter. You may not rewind using the audioHandle. This is because audio.loadSound() is optimized to share the audio data so you can play back multiple instances of the sound simultaneously (at different positions). Seeking (rewinding) the underlying data complicates this optimization.
In contrast, audio loaded with audio.loadStream() cannot be shared (you would load multiple instances of the same file if you needed multiple, simultaneous playback). So seeking the data does not cause a conflict. So generally you are expected to rewind using the audioHandle parameter for audio loaded with audio.loadStream(). But if you rewind streamed data using the channel parameter, it will automatically rewind as if you used the audioHandle parameter. So you are allowed to specify either parameter safely.
Also note that for files loaded with loadStream and are currently playing, you may not hear the audio immediate update until after the current buffer finishes playing. If you want seemingly instantaneous rewinding, you should stop the playback first using audio.stop(), rewind, then start playing.