Forum Discussion
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 mute button from beginning of the timeline and when my timeline reach audio 2 it get automatically play but my button is mute stage(selected).
19 Replies
- MarkSpermon-33eCommunity Member
The code Snorre has provided in this thread. Doesn't work in Storyline 360. I compared the code output for a Storyline 2 and a Storyline 360 module and it seems that in Storyline 360 they don't use the HTML audio element anymore to load audio files.
So the javasccripts that are on the forum don't work anymore.
Has anyone an idea how audio is played in Storyline360? And if there is a possibility to mute audio like in Storyline 2?Thanks,
Mark
- CK1CK1Community Member
Following. Looking for a solution as well.
- SnorrskiCommunity 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.
- AmitParshion919Community Member
This works. Thanks a lot :-)
Hello Anitha - I cannot assist with your JavaScript coding, but hopefully someone in the community will be able to chime in and assist you here.
- anithaduraisamyCommunity Member
my javascript coding is,
var a = document.getElementsByTagName('audio');
for(var i=0; i < a.length; i++)
{
if (a[i].volume>0)
{
a[i].volume=0;
}
else
{
a[i].volume=1;
}
}can you pls see this video....
if you know the answer help me........
thanks
Anitha
Related Content
- 1 year ago