YouTube:如何显示静音的嵌入视频


80

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

目前,我正在使用此功能,但无法正常工作:

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

你们谁都知道我该怎么做?

Answers:


84

更新

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

您的新代码将是:

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


6
不再工作了。使用youtube api(stackoverflow.com/a/41045251/353752
mwm

@FrankConijn,更简单的解决方案?答案是相同的,但是这个有一个例子,谁是第一个都没关系,有了例子,事情变得更容易了。
ICG DEVS

@ICGDEVS —您的评论没有任何意义。查看编辑的日期和我的评论-在另一个答案下,不要说“更简单”。
Frank Conijn

我不好,对不起。无论如何,在我的评论消失之前,您的评论不再有意义。
ICG DEVS


28

可接受的答案对我不起作用,我成功地遵循了本教程

基本上:

<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>

3
您也可以添加mute: 1其他内容playerVar,然后onReady不需要该事件。请务必在其后添加逗号,autohide: 0并注意不能使用,mute: 0因为这将被视为“垃圾邮件”。另请注意,刷新页面后,一旦您明确禁用了视频,该视频仍将被静音。
Simon_Weaver

11

这很容易。只需将Mutate = 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>

4

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

静音= 1


2
请添加一些解释如何回答
Hani

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>

截至2017年,此功能已正常运行,应被接受。
Manuel Di

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>

1

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

<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>


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>


-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>

2
请详细说明其工作原理以及原因。仅发布代码段对新手没有帮助。
herrbischoff

这只是不解决问题所在!
jankal'7

-5

试试这个

<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”

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.