Forum Discussion

anithaduraisamy's avatar
anithaduraisamy
Community Member
8 years ago

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

 

  • 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-f5's avatar
      RachelPorter-f5
      Community 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 = 1
      DS.appState.currentVolume($volume);

      When sound variable is false (sound off/muted), use JavaScript code:

      $volume = 0
      DS.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. 

  • Is there a way to do this at an individual audio object level rather than muting the entire project?