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.
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.
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...
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
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.