[Resolved] Perform Audio with Delay

Hi,

I’m just wondering if anyone can help with this. I’m pretty new to Corona and this seems basic enough but i’m having trouble with it.

I want to play some audio with delay when a page opens. Am I right to think that in order to do this the i need to create a function which plays the audio? Meaning that i’m performing the delay on the function rather than the audio. Hope this makes sense.

Thanks

Greg [import]uid: 155891 topic_id: 32759 reply_id: 332759[/import]

timer.performWithDelay(1000,function() audio.play(soundhandle) end)  

This will in 1000 milliseconds (i.e. 1 second) call an anonymous function (in JavaScript terminology) or a Lua enclosure (in Lua terms) that will call audio.play() to play your sound. The reason you need to wrap the call in the anonymous function is because you can’t pass parameters to the function which is required for audio.play(). This is identical to doing:

local function playMe()  
 audio.play(soundHandle)  
end  
  
timer.performWithDelay(1000, playMe)  

You would want to do the latter if you play to do this in multiple places in your code.
[import]uid: 19626 topic_id: 32759 reply_id: 130297[/import]

timer.performWithDelay(1000,function() audio.play(soundhandle) end)  

This will in 1000 milliseconds (i.e. 1 second) call an anonymous function (in JavaScript terminology) or a Lua enclosure (in Lua terms) that will call audio.play() to play your sound. The reason you need to wrap the call in the anonymous function is because you can’t pass parameters to the function which is required for audio.play(). This is identical to doing:

local function playMe()  
 audio.play(soundHandle)  
end  
  
timer.performWithDelay(1000, playMe)  

You would want to do the latter if you play to do this in multiple places in your code.
[import]uid: 19626 topic_id: 32759 reply_id: 130297[/import]