Master 'mute all' audio button

Hi All

I've been reading several posts on this subject and am I right to say that if I have numerous scenes, each with numerous audio elements, all added using timeline actions or upon scene load, there is no way of having a master 'mute all' button when set up like this?

At the end of the day the user can just use their device's audio controls, but after a lot of work of adding the audio in so many places etc they now want a 'mute all' button which I wish had been requested at the start of the build as I may have added the audio differently.

Do I need to start again? :frowning: Noobie classic error!

You may be able to do something if your audio elements are added to the scenes using audio tags construction.

But if placed on a scene or called by timeline/scene load then you will likely fall under the short fall of Hype audio and having no direct access to its audio context.

It's been a long standing request to get access and people do seem to keep hitting this wall.


@MaxZieb discovered a hack of getting to the Hype Audio context a while back.

But note that Max's work around is a Hack and could break at any time

I did a quick test using suspend() and resume()

Using it to suspend() any audio would work but any future triggers on a timeline or scene load would resume() ALL audio context and therefore negating the suspend() before the user manually used resume()

There may be a way of preventing that with audio context apis but I do cannot see anything obvious about it and the api is involved to say the least...

It may be simple or impossible.

Many thanks @MarkHunte thought it might be the case.

All my audio is on scene load, timeline actions etc so it is a no go. Nevermind. I'm not sure how to build audio in (I'm new to Hype) using audio tags and make them work at certain times or button actions etc There are lots of examples on here so I'll start learning :slight_smile:

Thanks again for the confirmation - appreciated.

Bob

at least you can stop all audio using Hypes custombehaviors

If you uncheck "Use low latency Web Audio API" in the Document Inspector, then Hype itself will use <audio> tags for its sounds.

Therefore you can then use JavaScript that iterates among all the audio elements in the document and pauses them via:

	var audioElements = document.getElementsByTagName("audio");
	for(var i = 0; i < audioElements.length; i++) {
		audioElements[i].pause();
	}
3 Likes

So if you run the above function 'On Scene Unload' this will pause all your audio elements.

Hah,

did not realise that.
Really good to know.

Still be good to initiate full mute which captures future triggers


As I mentioned above if you only run

var audioElements = document.getElementsByTagName("audio");
	for(var i = 0; i < audioElements.length; i++) {
		audioElements[i].pause();
	}

code on its own and one of timeline/click/scene play audio Actions were trigged then you will still get sound


If a full mute s wanted,

i.e don't play new sounds on any action trigger until un-muted.

You could do something like on the document load or on first scene load.
( no need to add to al scenes).

var audioElements = document.getElementsByTagName("audio");
	for(var i = 0; i < audioElements.length; i++) {
	 
audioElements[i].onplay = function(e) {
 
 if (hypeDocument.customData.muted  ){
 
  e.target.pause();
  
  } else {
  
   e.target.play();
 
  }
};
	}

And then your mute button is linked to

var audioElements = document.getElementsByTagName("audio");
	for(var i = 0; i < audioElements.length; i++) {
		audioElements[i].pause();
	}
 
		
		hypeDocument.customData.muted = (hypeDocument.customData.muted ? false : true )
	
	
	if (hypeDocument.customData.muted) {
	   hypeDocument.getElementById('muteButton').innerHTML = "un-Mute"
	 
	 } else {
	 
	  hypeDocument.getElementById('muteButton').innerHTML = "Mute"
	  
	  }

This seems to work. Once the mute button is pressed no new audio will play.
This includes Click initiated and Timeline and on scene load play audio triggers.

2 Likes