Restart sound effect on call

Hey guys,

I have a sound effect which lasts for 1 second. If this sound effect is called twice in  1 second, I want to stop the first one, so you can only hear the second one start to finish, in other words. No overlap for the soundeffect with itself.

How do achieve this? I’ve been looking through the audio documentation, but I’m not really finding anything useful. For starters If I decide to exclusively play the sound effect from lets say channel 1. I don’t even know how to run a check if channel 1 is currently playing.

Help greatly appreciated 

Hi @thomsip,

If this sound effect should never overlap, then it’s logical to play it on the same channel every time. In that case, I don’t think you need to actually check the channel or do anything special… just play the sound again on the same channel and the previous sound should stop (well, effectively be replaced by the new one).

If this doesn’t happen for some reason, you can check if the channel is active (a sound is either playing or paused on that channel). Then, if so, you can stop the audio by calling “audio.stop( [channel] )” and then play the new sound on the same channel. But, I don’t think this should be necessary… it should just replace the old with the new.

http://docs.coronalabs.com/api/library/audio/isChannelActive.html

http://docs.coronalabs.com/api/library/audio/stop.html

Also, if you haven’t yet seen the Audio guide, I suggest you read the entire thing to understand some subtle nuances of audio usage:

http://docs.coronalabs.com/guide/media/audioSystem/index.html

Best regards,

Brent

Hi @thomsip,

If this sound effect should never overlap, then it’s logical to play it on the same channel every time. In that case, I don’t think you need to actually check the channel or do anything special… just play the sound again on the same channel and the previous sound should stop (well, effectively be replaced by the new one).

If this doesn’t happen for some reason, you can check if the channel is active (a sound is either playing or paused on that channel). Then, if so, you can stop the audio by calling “audio.stop( [channel] )” and then play the new sound on the same channel. But, I don’t think this should be necessary… it should just replace the old with the new.

http://docs.coronalabs.com/api/library/audio/isChannelActive.html

http://docs.coronalabs.com/api/library/audio/stop.html

Also, if you haven’t yet seen the Audio guide, I suggest you read the entire thing to understand some subtle nuances of audio usage:

http://docs.coronalabs.com/guide/media/audioSystem/index.html

Best regards,

Brent