Preventing Audio Overlaps

Hello-
I have an app with multiple buttons in it. Each button plays an audio clip. But, when the buttons are pressed rapidly, all the audio starts playing at once and overlaps each other. This gets quite annoying, considering that up to 20-30 sounds could be playing at once. My question is how to make a button stop all other audio and then play its own sound.

My initial thought is to use stop.audio within the function. Is this correct, and - if so - how would I implement it within the button code? Here is my current code:

local onPhoneBtnLBTouch = function(event) if event.phase=="ended" then local myChannel = 6 local isChannelPlaying = audio.isChannelPlaying(myChannel) if isChannelPlaying then --nothing else audio.play( PhoneBtnLB\_audio, {channel=myChannel} ) end

Thank you greatly for your help!

[import]uid: 126736 topic_id: 24731 reply_id: 324731[/import]

See here; http://developer.anscamobile.com/reference/index/audiostop

[lua]audio.stop(myChannel)[/lua]

Call that if the channel is playing and it will be stopped :slight_smile: [import]uid: 52491 topic_id: 24731 reply_id: 100269[/import]

Awesome, thank you!

So, I assume that if I wanted all audio to stop, with the exception of my button sound, I could change:

if isChannelPlaying then   
 --nothing  

to

if isChannelPlaying then   
audio.stop(0)  

Is this correct? [import]uid: 126736 topic_id: 24731 reply_id: 100318[/import]

Yes, I believe that should do the trick :slight_smile: [import]uid: 52491 topic_id: 24731 reply_id: 100385[/import]