playing and stopping event sounds?

Hello,

I am trying to create an app where when they press a certain button that has the name of a sound on it, it plays. Now, what i am trying to accomplish is when they click on it, then it plays which i have down, and I also want so when they click on it while it is playing, it stops playing. What is the code to activate this? My code that i have so far for playing the sound is below.

local button = display.newImage( "Carengine.png" )  
function button:tap ( event )  
media.playEventSound( "Enginerev.caf" )  
end  
button:addEventListener("tap", button )  

Thank you for any help i get! I will very greatly appreciate it. [import]uid: 19836 topic_id: 8514 reply_id: 308514[/import]

@jsohu68

Have you checked out the Docs :
http://developer.anscamobile.com/content/multimedia-features

That might help you out if you are somewhat new with sounds, but ill try
to help you on what your trying to accomplish. one way you can do this
might not be the best way but should work fine or give you an idea
and like I said above the docs should have useful information for you.

You can add an event listener to your button like you did above but
instead of tap make it touch and your tap function can stop the sound.

So basically when you touch the object you will play sound when you
tap it you will stop it, if you check the docs out it will show you how
to stop a sound and judging by your code above you know how to
do tap functions and i`m assuming your familiar with touch functions.

hope this help if not ill try explain this better and post some sample
codes. (there are other ways to do what your trying to do but this is
just a simple cheap way to get you started or an idea) [import]uid: 30314 topic_id: 8514 reply_id: 30481[/import]

Thank you for the Doc! I read it and noticed the stop.sound function? it doesn’t tell me how to apply it to the code when you tap it then it stops playing as you said. The code in the Doc tells me how to stop it at a certain amount of time. May i please have a sample code on how to apply it? [import]uid: 19836 topic_id: 8514 reply_id: 30493[/import]