How can I prevent replaying once it's been playing already?i

Hi,

I’m trying to write an “audio manager” which I can ask to playback audio files that I want but it has to be aware of if it is playing that audio back already and do not attempt to play it.

I can put a Boolean variable for each audio but it’s not effective when I have 10+ audio files.

Thanks.

When you use loadSound or loadStream I’ll bet it hands you back a table – you could test that easily enough. If so, then just add your own property to that:
 

local laserSound = audio.loadSound("laserBlast.wav") laserSound.isPlaying = false  

 
When you play a sound, set that property to true and always use the onComplete callback – when that’s called, reset the isPlaying property to false.
 
Just theory, as I haven’t done that myself. But it might work. :slight_smile:
 
Jay

When you use loadSound or loadStream I’ll bet it hands you back a table – you could test that easily enough. If so, then just add your own property to that:
 

local laserSound = audio.loadSound("laserBlast.wav") laserSound.isPlaying = false  

 
When you play a sound, set that property to true and always use the onComplete callback – when that’s called, reset the isPlaying property to false.
 
Just theory, as I haven’t done that myself. But it might work. :slight_smile:
 
Jay