How to mute an html5 video player using jQuery

后端 未结 3 1657
刺人心
刺人心 2020-11-27 17:23

I\'ve found how to pause and play the video using jquery

$(\"video\").get(0).play();
$(\"video\").get(0).pause();

But I can\'t find t

3条回答
  •  悲哀的现实
    2020-11-27 18:00

    If you don't want to jQuery, here's the vanilla JavaScript:

    ///Mute
    var video = document.getElementById("your-video-id");
    video.muted= true;
    
    //Unmute
    var video = document.getElementById("your-video-id");
    video.muted= false;
    

    It will work for audio too, just put the element's id and it will work (and change the var name if you want, to 'media' or something suited for both audio/video as you like).

提交回复
热议问题