音频静音-取消静音图标

时间:2020-09-24 01:17:41

标签: javascript html html5-audio

我想制作一个让您静音或取消静音的图标。图标本身可以工作,但是音频不会播放。这是代码:

static void RevealStr(StringBuilder str, int i) {
    //base case: prints each possibility when reached
    if(str.length() == i) {
        System.out.println(str);
        return;
    }
    //recursive step if wild card (*) found
    if(str.charAt(i) == '*') {
        //exploring permutations for 0 and 1 in the stack frame
        for(char ch = '0'; ch <= '1'; ch++) {
            //making the change to our string
            str.setCharAt(i, ch);
            //recur to reach permutations
            RevealStr(str, i+1);
            //undo changes to backtrack
            str.setCharAt(i, '*');
        }
        return;
    }
    else
        //if no wild card found, recur next char
        RevealStr(str, i+1);
}

有人可以帮助我吗?

(也是,我正在使用w3schools的声音)

1 个答案:

答案 0 :(得分:1)

x.muted是解决方案:

function changeImage() {
    var x = document.getElementById("myaudio");
    if (
        document.getElementById("imgClickAndChange").src ==
        "https://www.iconfinder.com/data/icons/octicons/1024/unmute-512.png"
    ) {
        document.getElementById("imgClickAndChange").src =
            "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Mute_Icon.svg/1200px-Mute_Icon.svg.png";
        
        x.muted = true;
    } else {
        document.getElementById("imgClickAndChange").src =
            "https://www.iconfinder.com/data/icons/octicons/1024/unmute-512.png";
        
        
        x.muted = false;
    }
}
<audio id="myaudio" controls loop>
  <source src="https://www.w3schools.com/jsref/horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<img src="https://www.iconfinder.com/data/icons/octicons/1024/unmute-512.png" 
            style="height: 80px; width: 80px" id="imgClickAndChange" onclick="changeImage()"  />
</p>

相关问题