[SOLVED] Can't get SoundComponent "isPlaying()" method to work

Hey,

It must be something I am overlooking, but I can’t for the life of me get the isPlaying('slotname') method of PlayCanvas’ SoundComponent to work. See documentation

I have an entity with a SoundComponent with a slot named ‘Slot1’ and the following code snippet:

this.entity.sound.play('Slot1'); //Works fine
this.entity.sound.isPlaying('Slot1'); //For some reason throws error

Anyone see why this doesn’t work?

Hi @Astra,

I see you commented that you are receiving an error. Could you elaborate on what error you’re receiving?

This returns true or false. So I don’t think it’s useable like this.

ah, ok. my bad. the way I’m actually using it is like this:

if(!this.entity.sound.isPlaying('Slot1')){
   this.entity.sound.play('Slot1');
}

just thought it be easier to explain with the other example :sweat:

and the error I’m getting is:
“this.entity.sound.isPlaying is not a function”

(however, this.entity.sound.play is clearly a function since that alone works just fine)

It’s a quite new function and I think you use it correct now. I didn’t use it myself yet, so not sure what could be the problem.

Maybe you can try to use the old method?

if (!this.entity.sound.slot('Slot1').isPlaying) {
    this.entity.sound.play('Slot1');
}

hm… weird now I’m getting “this.entity.sound.slot is not a function”…
I’m guessing it might be something weird with our project setup?
I’ll try with a fresh project

Tried with a fresh project. but still not working :confused:
https://playcanvas.com/editor/scene/1699742

Can you please take a look @yaustar?

Looks like the function was added for 1.62 engine release (not out yet) and isn’t in 1.61.

I’m not sure why the docs have been released for 1.62 :thinking: Will have to fix that when I get a chance

For now, use the method explained here: Prevent a sound from starting repeatedly · Issue #4885 · playcanvas/engine · GitHub

I already suggested this, but @Astra mentioned this give the same error.

Works fine here: PlayCanvas 3D HTML5 Game Engine

1 Like

I double checked in the new blank project and the “this.entity.sound.slot(‘Slot1’).isPlaying” call worked there, so I guess there was something with our larger project that was interfering or something.