How to unmute html5 video with a muted prop

后端 未结 4 967
抹茶落季
抹茶落季 2021-02-08 18:28

I\'ve created a simple video block with muted (for mobile autostart) but now i can not change the mute state...

I used that repository , fiddle link would be great.

4条回答
  •  名媛妹妹
    2021-02-08 19:32

    Try this:

    function toggleMute() {
    
      var video=document.getElementById("myVideo");
    
      video.muted = !video.muted;
    
    }
    

    Check example here

    If your own code is not working, try adding an id to your video/element you want the click to register on and using:

    var video=document.getElementById("myVideo") ;   
    
    $(video).on("click", function(e){
      video.muted = !video.muted;
    });
    

提交回复
热议问题