Play Audio at random intervals

Hi everyone,

I wonder if anyone could help me with this. I’m fairly new to Corona and i’m trying to create a piece of code which will play an clip at random intervals. So it plays the sound, then plays it again a few seconds later at a random time.

Any help would be greatly appreciated,

Thanks

Greg [import]uid: 155891 topic_id: 33283 reply_id: 333283[/import]

  
local randomTimer = nil  
  
local function queueSound()  
 audio.play("yoursound")  
 if randomTimer then  
 timer.cancel(randomTimer)  
 randomTimer = nil  
 end  
 randomTimer = timer.performWithDelay((math.random(5)+1) \* 1000, queueSound)  
end  

This will have a minimum 1 second delay and up to 6 seconds.
Totally untested. [import]uid: 19626 topic_id: 33283 reply_id: 132239[/import]

  
local randomTimer = nil  
  
local function queueSound()  
 audio.play("yoursound")  
 if randomTimer then  
 timer.cancel(randomTimer)  
 randomTimer = nil  
 end  
 randomTimer = timer.performWithDelay((math.random(5)+1) \* 1000, queueSound)  
end  

This will have a minimum 1 second delay and up to 6 seconds.
Totally untested. [import]uid: 19626 topic_id: 33283 reply_id: 132239[/import]