Forum Discussion
Mute audio using javascript
This seems to work well:
//mute/unmute
// Use the global DS object if it exists, otherwise try require:
var appState = window.DS ? DS.appState : require("helpers/appState");
appState.onToggleVolume();
My challenge is that when users restart the course if the volume is toggled off it stays off and my speaker visual stops matching the sound. :/
Any ideas on how to turn the sound back on...
I was thinking about having my reset button toggle the java script but the problem is if the sound is on it is now off and I have the same issue ... if that makes any sense...
Edit:
Here's the code you can either execute on the first slide or at the end to reset the volume to on.
var appState = window.DS ? DS.appState : require("helpers/appState");
appState.setVolume(1);
There is probably a better javascript code you could use that is like
getSound level if 0 set your sound variable to false
if 1 do nothing
- RachelPorter-f52 years agoCommunity Member
Hi there,
I came across your comment when searching for a solution to the exact same issue. I was able to work out the JavaScript code so I thought I would share.
When sound variable is true (sound on), use JavaScript code:
$volume = 1DS.appState.currentVolume($volume);When sound variable is false (sound off/muted), use JavaScript code:
$volume = 0DS.appState.currentVolume($volume);When your module restarts, it will return to whatever your default value is for your sound variable (in my case, sound on) and should therefore match your audio button.
Related Content
- 11 months ago
- 3 months ago