Forum Discussion
anithaduraisamy
8 years agoCommunity Member
Mute audio using javascript
Hi guys,
i want to create my own mute/unmute audio button using articulate.i done this but i have a small problem.
problem:
i have three to four audio within a single slide.
when i click mut...
Snorrski
8 years agoCommunity Member
Hi Anitha
I would suggest that you add an extra variable, and another trigger:
In storyline add the variable "muted", which could be a true/false. Then use it in your code.
var player = GetPlayer();
var muted = player.GetVar("muted");
var a = document.getElementsByTagName('audio');
for(var i=0; i < a.length; i++)
{
if (a[i].volume>0)
{
a[i].volume=0;
player.SetVar("muted", true)
}
else
{
a[i].volume=1;
player.SetVar("muted", false)
}
}
This will tell set an custom variable which you can use to check if the use has chosen to mute the audio.
Then for each audio piece, add an extra trigger to run at the same time as the next audio file starts with the following code:
var player = GetPlayer();
var muted = player.GetVar("muted");
if (muted)
{
a[i].volume=0;
}
This will check if the user has chosen to mute the audio, and remute if so.
- AmitParshion9193 years agoCommunity Member
This works. Thanks a lot :-)