@@ -221,12 +221,16 @@ export class PlayerAudio {
221221
222222 // if media element source also destroy the media element? (for each song?)
223223 songsQueue . forEach ( ( sound ) => {
224- if ( sound . sourceNode instanceof MediaElementAudioSourceNode ) {
225- if ( typeof sound . sourceNode . mediaElement !== 'undefined' ) {
226- sound . sourceNode . mediaElement . remove ( ) ;
224+ if ( sound . sourceNode !== null ) {
225+ if ( sound . sourceNode instanceof MediaElementAudioSourceNode ) {
226+ if ( typeof sound . sourceNode . mediaElement !== 'undefined' ) {
227+ sound . sourceNode . mediaElement . remove ( ) ;
228+ }
227229 }
230+ // disconnect no matter if AudioBufferSourceNode
231+ // or MediaElementAudioSourceNode
232+ sound . sourceNode . disconnect ( ) ;
228233 }
229- sound . sourceNode . disconnect ( ) ;
230234 } ) ;
231235
232236 this . _disconnectPlayerGainNode ( ) ;
@@ -351,8 +355,10 @@ export class PlayerAudio {
351355
352356 protected _disconnectPlayerGainNode ( ) : void {
353357
354- this . _audioNodes . gainNode . disconnect ( ) ;
355-
358+ if ( this . _audioNodes . gainNode !== null ) {
359+ this . _audioNodes . gainNode . disconnect ( ) ;
360+ }
361+
356362 this . _audioNodes . gainNode = null ;
357363
358364 }
@@ -368,18 +374,12 @@ export class PlayerAudio {
368374
369375 }
370376
371- public async disconnectSound ( sound : ISound ) : Promise < void > {
372-
373- if ( sound . gainNode !== null ) {
374- //sound.gainNode.disconnect();
375- } else {
376- throw new PlayerError ( 'can\'t destroy as no source node in sound' ) ;
377- }
377+ public async cleanUpAudiBufferSourceNode ( sound : ISound ) : Promise < void > {
378378
379379 if ( sound . sourceNode instanceof AudioBufferSourceNode ) {
380- // the audio buffer source node we set it to undefined, to let it get destroyed
381- // by the garbage collector as you can't reuse an audio buffer source node
382- // ( after it got stopped) as specified in the specs
380+ // the audio buffer source node we set it to null, so that it gets destroyed
381+ // by the garbage collector ( as you can't reuse an audio buffer source node,
382+ // after it got stopped) as specified in the specs
383383 sound . sourceNode = null ;
384384 }
385385
0 commit comments