Muting an embedded vimeo video

前端 未结 12 2260
攒了一身酷
攒了一身酷 2020-12-14 07:42

On a website I am building I have a vimeo video embedded. The client needs to keep the sound on the video obviously for people that find it on vimeo. However for her website

12条回答
  •  悲&欢浪女
    2020-12-14 08:04

    **Here is my solution: http://jsfiddle.net/jakeoblivion/phytdt9L/5/

    (You will need your own play/pause mute/unmute icons)

      //load video muted
      var video = $("#myvideo");
      video.vimeo("play");
      video.vimeo("setVolume", 0);
    
        //toggle play/pause
      $('#play-pause').click(function() {
        $(this).toggleClass('play');
        if ($(this).hasClass('play')) {
          //pause video
          video.vimeo("pause");
          $(this).css('background', 'pink');
        } else {
          //unpause video
          video.vimeo("play");
          $(this).css('background', 'blue');
        }
      });
    
      //toggle mute/unmute
      $('#mute-unmute').click(function() {
        $(this).toggleClass('mute');
        if ($(this).hasClass('mute')) {
          //unmute video
      video.vimeo("setVolume", 1);
          $(this).css('background', 'green');
    
        } else {
          //mute video
      video.vimeo("setVolume", 0);
          $(this).css('background', 'red');
        }
      });
    

    Spent ages trying and nothing seemed to work to.

    I just wanted to have a Vimeo autoplay muted (volume 0) with simple Play/Pause Mute/Unmute controls, instead of their default ones. (feel free to use icons instead of the temporary colours I put).

    (if you want to add the default controls back but keep muted, remove "?background=1". By default background=1 will set video.vimeo("setVolume", 0) and hide controls, so I also added the mute on load without the background=1 set).

    Also note: "You’ll need to be running on a web server instead of opening the file directly in your browser. JS security restrictions will prevent the API from working when run locally."

提交回复
热议问题