Picture of Henrik Aabom
Stop sound on page change?
by Henrik Aabom - Thursday, 1 September 2016, 9:23 AM
 

Hi everyone

Maybe someone can point me en the right direction here.

I've created a component that plays a sound file using an audio element:

var _audioEle = document.createElement('audio');

But, the element keeps playing when the user changes from one page to another. For instance when the user clicks back to the menu.

Is there a way to detect when the user leaves a page and then stop the audio element? For instance with:

_audioEle.pause();

 

Any help here will be much appreciated

Henrik

Picture of Matt Leathes
Re: Stop sound on page change?
by Matt Leathes - Monday, 5 September 2016, 3:07 PM
 

You can see how we do it in our audio extension here.

If you're just using audio within a component then all you need to do is include a remove function, just like the media component has.

Picture of Henrik Aabom
Re: Stop sound on page change?
by Henrik Aabom - Friday, 9 September 2016, 7:06 AM
 

Thank you Matt. Great help :)