File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
packages/dev/core/src/AudioV2 Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -252,5 +252,7 @@ export abstract class AbstractSound extends AbstractSoundSource {
252252 this . _state = SoundState . Stopped ;
253253 this . onEndedObservable . notifyObservers ( this ) ;
254254 }
255+
256+ instance . dispose ( ) ;
255257 } ;
256258}
Original file line number Diff line number Diff line change @@ -358,8 +358,11 @@ class _WebAudioStaticSoundInstance extends _StaticSoundInstance implements IWebA
358358 const restart = this . _state === SoundState . Starting || this . _state === SoundState . Started ;
359359
360360 if ( restart ) {
361- this . stop ( ) ;
361+ // Stop source node without sending `onEndedObservable` so instance's `dispose` function is not called.
362+ const sourceNode = this . _sourceNode ;
362363 this . _deinitSourceNode ( ) ;
364+ sourceNode ?. stop ( ) ;
365+ this . _state = SoundState . Stopped ;
363366 }
364367
365368 this . _options . startOffset = value ;
@@ -467,12 +470,13 @@ class _WebAudioStaticSoundInstance extends _StaticSoundInstance implements IWebA
467470 return ;
468471 }
469472
470- this . _setState ( SoundState . Stopped ) ;
471-
472473 const engineStopTime = this . engine . currentTime + ( options . waitTime ?? 0 ) ;
473474 this . _sourceNode ?. stop ( engineStopTime ) ;
474475
475- this . engine . stateChangedObservable . removeCallback ( this . _onEngineStateChanged ) ;
476+ if ( options . waitTime === undefined || options . waitTime <= 0 ) {
477+ this . _setState ( SoundState . Stopped ) ;
478+ this . engine . stateChangedObservable . removeCallback ( this . _onEngineStateChanged ) ;
479+ }
476480 }
477481
478482 protected override _connect ( node : AbstractAudioNode ) : boolean {
You can’t perform that action at this time.
0 commit comments