On Sound Done? : )

Sound.onEndedObservable

How to callback on Sound Ended?

https://doc.babylonjs.com/api/classes/babylon.sound#onendedobservable

https://doc.babylonjs.com/playground/?code=onEndedObservable

Tried to emulate Sound.onEndedObservable. Will be good for googlers.

second debugger didn’t trigger. Maybe I am missing something.

debugger;
nx.sonics.footsteps1= new BABYLON.Sound("footsteps1","./or2.mp3", nx.scene, null, { loop: false, autoplay: false });
nx.sonics.footsteps1.onEndedObservable = new BABYLON.Observable();
nx.sonics.footsteps1.onEndedObservable.add(function(value) {   debugger;   })
nx.sonics.footsteps1.play(); 

How to get second debugger to fire on Sound Ended?

Babylon.js engine (v3.0-alpha)

Does it need something else?

Thankz,

:grin:

Why are you recreating the observable? It is already initialized during construction.

1 Like

thanks RaananW I like your work.

removed the initializer

RESULT: Uncaught TypeError: Cannot read property ‘add’ of undefined

Thanks :blush:

I just noticed the version you are using. Is it really Babylon 3? I’m not sure this observable was added back then. Can you try with a newer version?

No. I cant, for artistic purposes. : )

And Observable is in there. Double-checked that.

Anyway. I write custom .isPlaying() Loop. Np.

Thanks for your help. : )

good2cu

Did this:

            let soundEndDamper=0;
            nx.scene.registerBeforeRender(function soundEndLoopz() { 
                if(++soundEndDamper%100===0){return} //frame-damper-.
                if(nx.sonics.footsteps1.isPlaying&&!nx.sonics.footsteps1.endSound){ nx.sonics.footsteps1.endSound=1; } //init
                else if(!nx.sonics.footsteps1.isPlaying&&nx.sonics.footsteps1.endSound){ nx.scene.unregisterBeforeRender(soundEndLoopz); /*self-removing-.*/ } //done
            });

It is a self removing animation loop pattern, called LOOPZ pattern (for unique search).

would prefer Observer BUS pattern. But gotta keep moving.

Thanks for confirming.

:eagle: : )