Jump to content
GreenSock

heartglen

Muting all audio with window.focus/blur

Recommended Posts

Greetings.

 

I've several audio files in my project (html based animations), playing in different actions. I labeled every sound as;

 

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

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

audio1 .setAttribute('src', 'audio/audio1.mp3');

audio2.setAttribute('src', 'audio/audio2.mp3'); etc.

 

And playing them during animation with TweenMax (like audio1.play, TweenMax.to(audio1, 1, {volume:0...)

 

I'm trying to mute all sounds if visitor leaves to another tab; with $(window).blur and focus functions,

but active audio is changing during animation, so i need to get back to active audio file when user returns the tab. 

 

How can i mute the volume of the tab?

 

Thank you very much in advance for all your help.

Link to comment
Share on other sites

Hi I'm not exactly sure of what you need to do or how your issue relates to GSAP.

 

If you want to mute all the audio at a certain time you could build an Array with all your references to your audio files and provide the array to a to() tween like

var audio = [audio1, audio2, audio3];

// mute all audio instantly:
TweenLite.set(audio, {volume:0});
//or fade it out
TweenLite.to(audio, 0.5, {volume:0});
  • Like 4
Link to comment
Share on other sites

Hi Carl,  that was exactly what i was looking for. Instead of a direct muting, i prefer to use fade out the volume with tweenLite/Max; creating an array solved it. Thanks you very much.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×