Javascript to MUTE audio?

Aug 09, 2012

Is it possible to MUTE audio in Storyline? I'm working on a course with a ground-up custom interface with a button that's supposed to mute/unmute - not pause/play or stop/play - the audio.

Are there any Javascript gurus out there who know if this is possible? And if so, can you provide the scripts for mute and unmute? That would SO make my day.

Dazed and confused...

Patrice

141 Replies
Ashley Terwilliger-Pollard

Thanks Deepak for sharing your solution here, and although this forum discussion is a bit older I'm sure it'll still be helpful to others who come across it. I did also want to mention that you're welcome and encouraged to share any examples, or step by step instructions that may assist other users as they look to replicating your solution.

Ajay Khatri

Hi Everyone, 

I have used javascript code to set volume to 0 (mute audio) and set volume to 0.8 (unmute audio)

the code used is:

$('audio').each(function(){
this.volume=0; //mute audio
});

$('audio').each(function(){
this.volume=0.8; //unmute audio
});

when testing from a web server, this code is working fine in IE11, Firefox but not working in Chrome.

this code is working fine when reviewed locally in IE11, Firefox and Chrome.

Can anyone suggest me a solution for this issue?

Thanks in advance

Ajay Khatri

Ajay Khatri

Hi Ravindra,

Yes I got the solution in another thread, I am posting the solution here too so you can see here.

to mute audio I have used this code and it is working fine:

if (document.location.href.indexOf('html5') < 0) {
} else {

var player = GetPlayer();
Audio.setMasterVolume(0);
$('audio').prop('volume','0');
}

to unmute audio I have used this code and it is working fine:

if (document.location.href.indexOf('html5') < 0) {
} else {

var player = GetPlayer();
Audio.setMasterVolume(0.8);
$('audio').prop('volume','0.8');
}

the condition mentioned above ensures that these commands work only in HTML5 version of the course.

Ajay Khatri

Hi Anitha

This code is applied to triggers on the audio on/off buttons.

on audio off/mute button, add a new trigger and select execute Javascript and paste the following code:

if (document.location.href.indexOf('html5') < 0) {
} else {

var player = GetPlayer();
Audio.setMasterVolume(0);
$('audio').prop('volume','0');
}

On audio on button, 

add a new trigger and select execute Javascript and paste the following code:

if (document.location.href.indexOf('html5') < 0) {
} else {

var player = GetPlayer();
Audio.setMasterVolume(0.8);
$('audio').prop('volume','0.8');
}

please note that this code will work only in HTML 5 version of the publish course content.

and for Flash version of the published content you can use the mute toggler as explained in this thread.

give me a shout if you need any more help in Articulate Storyline.

Regards

Ajay Khatri

Ajay Khatri

Hi Anitha,

Apologies for a late reply, I had been bit busy.

Yes, you need to implement 2 different approaches to control the audio in Flash and HTML5.

HTML5 -  coding I have explained above.

Flash - Please read this thread completely and Implement the solution provided by Steve, it works perfectly for Flash version.

These both have to be applied together, mute toggler will work only in Flash version and the HTML5 code will work in HTML5 only.

Let me know if still you need any more help.

Regards,

Ajay Khatri

Ashley Terwilliger-Pollard

Hi Heinrich,

I can't speak to the Javascript element - but if it's not working in your LMS it may be worth testing at SCORM Cloud. It's a free standard for testing LMS content and if it works there you should reach out to your LMS team. Take a look at the directions here for how to test in SCORM Cloud. 

Heinrich Maingardt

Hi Ashley,

Thanks for the tip. I've tested it in the ScormCloud. There it does not work unfortunately.
I get the following error message in the console:

app.min.js:12 actionator::exeJavaScript - Cannot read property 'volume' of undefined

And when I try over the console:

jQuery('audio').prop('volume','0');

I get the following:

[prevObject: init(1), context: document, selector: "audio"]

context:document

length:0

prevObject:init(1)
selector:"audio"
__proto__:Object(0)

It seems, that no audio tags found.