YouTube:如何呈现嵌入声音静音的视频

时间:2016-01-27 17:51:29

标签: html html5 youtube youtube-iframe-api

我正在尝试嵌入一个声音静音的视频,但我无法弄清楚它是如何工作的。

目前我正在使用此功能但不起作用:

<iframe src="https://www.youtube.com/embed/uNRGWVJ10gQ?rel=0&amp;autoplay=1" width="560" height="315" frameborder="0" allowfullscreen></iframe>

你们中的任何人都知道我怎样才能做到这一点?

13 个答案:

答案 0 :(得分:93)

对我来说,使用&autoplay=1&mute=1

答案 1 :(得分:39)

<强>更新

&mute=1添加到网址的末尾。

您的新代码将是:

&#13;
&#13;
<iframe src="https://www.youtube.com/embed/uNRGWVJ10gQ?rel=0&amp;autoplay=1&mute=1" width="560" height="315" frameborder="0" allowfullscreen></iframe>
&#13;
&#13;
&#13;

旧答案

您必须添加Javascript才能将音频静音。在iframe中添加ID:              然后使用javascript检索id:       var myVideo = iframe.getElementById(&#39; myVideo&#39;); myVideo.mute();

另请参阅Youtube API参考https://developers.google.com/youtube/js_api_reference?csw=1

中的静音部分

问题: How do I automatically play a Youtube video (IFrame API) muted?

答案 2 :(得分:28)

获取源网址,例如:

  

http://www.youtube.com/embed/1r2a3n4d5o6m/

然后将 ?mute=1 添加到结尾,所以:

  

http://www.youtube.com/embed/1r2a3n4d5o6m/?mute=1

Google's documentation中还有其他玩家参数。

答案 3 :(得分:17)

接受的答案对我不起作用,我跟着this tutorial取得了成功。

基本上:

<div id="muteYouTubeVideoPlayer"></div>
<script async src="https://www.youtube.com/iframe_api"></script>
<script>
 function onYouTubeIframeAPIReady() {
  var player;
  player = new YT.Player('muteYouTubeVideoPlayer', {
    videoId: 'YOUR_VIDEO_ID', // YouTube Video ID
    width: 560,               // Player width (in px)
    height: 316,              // Player height (in px)
    playerVars: {
      autoplay: 1,        // Auto-play the video on load
      controls: 1,        // Show pause/play buttons in player
      showinfo: 0,        // Hide the video title
      modestbranding: 1,  // Hide the Youtube Logo
      loop: 1,            // Run the video in a loop
      fs: 0,              // Hide the full screen button
      cc_load_policy: 0, // Hide closed captions
      iv_load_policy: 3,  // Hide the Video Annotations
      autohide: 0         // Hide video controls when playing
    },
    events: {
      onReady: function(e) {
        e.target.mute();
      }
    }
  });
 }

 // Written by @labnol 
</script>

答案 4 :(得分:9)

这很容易。只需将 mute = 1 添加到iframe的src参数即可 例如:

<iframe src="https://www.youtube.com/embed/uNRGWVJ10gQ?controls=0&mute=1&showinfo=0&rel=0&autoplay=1&loop=1&playlist=uNRGWVJ10gQ" frameborder="0" allowfullscreen></iframe>

答案 5 :(得分:4)

&#13;
&#13;
<iframe  src="https://www.youtube.com/embed/7cjVj1ZyzyE?autoplay=1&loop=1&playlist=7cjVj1ZyzyE&mute=1" frameborder="0"  allowfullscreen></iframe>
&#13;
&#13;
&#13;

静音= 1

答案 6 :(得分:2)

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/ObHKvS2qSp8?list=PLF8tTShmRC6uppiZ_v-Xj-E1EtR3QCTox&autoplay=1&controls=1&loop=1&mute=1" frameborder="0" allowfullscreen></iframe>



<iframe width="560" height="315" src="https://www.youtube.com/embed/ObHKvS2qSp8?list=PLF8tTShmRC6uppiZ_v-Xj-E1EtR3QCTox&autoplay=1&controls=1&loop=1&mute=1" frameborder="0" allowfullscreen></iframe>

答案 7 :(得分:1)

来源:https://developers.google.com/youtube/iframe_api_reference

   <div id="player"></div>
    <script>

          var tag = document.createElement('script');
          tag.src = "https://www.youtube.com/iframe_api";
          var firstScriptTag = document.getElementsByTagName('script')[0];
          firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

          var player;
          function onYouTubeIframeAPIReady() {
            player = new YT.Player('player', {
              height: '720',
              width: '1280',
              videoId: 'M7lc1UVf-VE',
              playerVars :{'autoplay':1,'loop':1,'playlist':'M7lc1UVf-VE','vq':'hd720'},
              events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
              }
            });
          }

          function onPlayerReady(event) {
               event.target.setVolume(0);
           event.target.playVideo();
          }

          var done = false;
          function onPlayerStateChange(event) {
            if (event.data == YT.PlayerState.PLAYING && !done) {
        //      setTimeout(stopVideo, 6000);
                      done = true;
            }
               event.target.setVolume(0);
          }
    </script>

答案 8 :(得分:1)

我要感谢在此区域发布以下代码的朋友。我终于解决了一整天都要处理的问题。

&#13;
&#13;
<div id="muteYouTubeVideoPlayer"></div>
                            <script async src="https://www.youtube.com/iframe_api"></script>
                            <script>
                                function onYouTubeIframeAPIReady() {
                                    var player;
                                    player = new YT.Player('muteYouTubeVideoPlayer', {
                                        videoId: 'xCIBR8kpM6Q', // YouTube Video ID
                                        width: 1350, // Player width (in px)
                                        height: 500, // Player height (in px)
                                        playerVars: {
                                            autoplay: 1, // Auto-play the video on load
                                            controls: 0, // Show pause/play buttons in player
                                            showinfo: 0, // Hide the video title
                                            modestbranding: 0, // Hide the Youtube Logo
                                            loop: 1, // Run the video in a loop
                                            fs: 0, // Hide the full screen button
                                            cc_load_policy: 0, // Hide closed captions
                                            iv_load_policy: 3, // Hide the Video Annotations
                                            autohide: 0, // Hide video controls when playing
                                            rel: 0 
                                        },
                                        events: {
                                            onReady: function(e) {
                                                e.target.setVolume(5);
                                            }
                                        }
                                    });
                                }

                                // Written by @labnol

                            </script>
&#13;
&#13;
&#13;

答案 9 :(得分:0)

只需通过mute=1

例如:

<iframe id="myVideo" src=https://www.youtube.com/embed/k0DN-BZrM4o?rel=0&amp;autoplay=1;mute=1" width="100%" height="600" frameborder="0" allowfullscreen></iframe>

答案 10 :(得分:-1)

也在寻找解决方案,但我没有通过iframe,我的链接到images / video.mp4 - 发现这个https://www.w3schools.com/tags/att_video_muted.asp - 我只是添加&lt;视频控件静音&gt; (CSS / HTML 5解决方案),但我不需要JS ......

答案 11 :(得分:-3)

<iframe width="560" height="315" src="https://www.youtube.com/embed/ULzr7JsFp0k?list=PLF8tTShmRC6vp9YTjkVdm1qKuTimC6K3e&rel=0&amp;autoplay=1&controls=1&loop=1" rel=0&amp frameborder="0" allowfullscreen></iframe>

答案 12 :(得分:-4)

试试这个

<iframe width="420" height="315" src="http://www.youtube.com/embed/
HeQ39bLsoTI?autoplay=1&cc_load_policy=1" volume="0" frameborder="0"
allowfullscreen></iframe>

不要忘记写volume =“0”