SoundAS icon indicating copy to clipboard operation
SoundAS copied to clipboard

How to check that sound is already load?

Open katopz opened this issue 12 years ago • 5 comments

Hi, noobs here!

question is... How to check that sound is already load? so i can just play if sound already load... far as i try is

var si:SoundInstance = SoundAS.getSound("somesound");

but at present it will throw error if it not exist, i did expected null for first load then call SoundAS.loadSound if si is null e.g.

if(!si)
    SoundAS.loadSound("somesound.mp3", "somesound");

and if i load sound via SoundAS.loadSound again without check for existing SoundAS.loadCompleted is seem to be never fire for second load same url and type.

btw, i don't think it's a good idea to try catch there. "null for non exist SoundAS.getSound" should be better there.

Thanks

katopz avatar Jul 23 '13 15:07 katopz

I have a same problem.

public function getSound(type:String, forceNew:Boolean = false):SoundInstance

if specfied type is not found, it will throw new error, and this error not catch in SoundManager.

so is should possible add catch in that "try...finally" code block ? or if not found specfied sound, do not fire a error, just trace a message?

or maybe add a new method containSound?

lynxerzhang avatar Jul 04 '14 03:07 lynxerzhang

I changed it locally so that getSound returns null instead of throwing an error. Though a containsSound would be good.

MSGhero avatar Jul 04 '14 03:07 MSGhero

I did the same on my side.

Adolio avatar Jul 04 '14 13:07 Adolio

yes please add support for containsSound!

iiilx avatar Oct 31 '14 18:10 iiilx

SoundAS.getSound('XXX').sound.addEventListener(Event.COMPLETE,COMPLETE); SoundAS.getSound('XXX').sound.addEventListener(IOErrorEvent.IO_ERROR,IO_ERROR);

Adol avatar Dec 21 '16 08:12 Adol