如何静音;取消静音播放器按钮?

时间:2014-10-08 20:08:36

标签: javascript mute

我正在尝试构建一个假设静音和取消静音我的播放器的按钮。 出于某种原因,我只能静音,但不能取消静音。 播放/暂停按钮相同的功能正常工作... 任何人都有iade?

<html>
<head></head>
<body>
 <input type='button'  onclick="muteUnMute()"  value='Mute' class="btn_random" id="muteunmute"/>
 <audio controls="controls" preload autoplay="autoplay" id="audio1" volume="1.0"></audio>       

<script type="text/javascript">
  function muteUnMute() {
        var muteSound = document.getElementById("audio1");
        x = new Boolean(muteSound.muted=false);

        if (x) {
          document.getElementById('audio1').muted = true;
          document.getElementById("muteunmute").value="Un-Mute";
       } else {
          document.getElementById('audio1').volume="1.0";
          document.getElementById("muteunmute").value="Mute";
       }
    }

</script>
</body>

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以将功能简化为:

function muteUnMute() {
    document.getElementById('audio1').muted = !document.getElementById('audio1').muted;
    document.getElementById("muteunmute").value = (document.getElementById("muteunmute").value == "Mute") ? "Un-Mute" : "Mute";
}