How to mute an html5 video player using jQuery

后端 未结 3 1619
刺人心
刺人心 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 17:45
    $("video").prop('muted', true); //mute
    

    AND

    $("video").prop('muted', false); //unmute
    

    See all events here

    (side note: use attr if in jQuery < 1.6)

    0 讨论(0)
  • 2020-11-27 17:58

    Are you using the default controls boolean attribute on the video tag? If so, I believe all the supporting browsers have mute buttons. If you need to wire it up, set .muted to true on the element in javascript (use .prop for jquery because it's an IDL attribute.) The speaker icon on the volume control is the mute button on chrome,ff, safari, and opera for example

    0 讨论(0)
  • 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).

    0 讨论(0)
提交回复
热议问题