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

use*_*482 65 html youtube html5 youtube-iframe-api

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

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

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

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

小智 98

对我来说工作 &autoplay=1&mute=1


Dev*_*ugh 57

更新

添加&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>
Run Code Online (Sandbox Code Playgroud)

老答案

你将不得不添加Javascript来静音音频.在iframe中添加ID:然后使用javascript检索id:var myVideo = iframe.getElementById('myVideo'); myVideo.mute();

另请参阅Youtube API参考中的静音部分 https://developers.google.com/youtube/js_api_reference?csw=1

问题是: 如何自动播放Youtube视频(IFrame API)静音?

  • 不再起作用了.使用youtube api(/sf/answers/2873167601/) (5认同)

Joe*_*don 29

以源URL为例,例如:

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

然后添加?mute=1到最后,所以:

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

Google的文档中还有其他播放器参数.


pau*_*aul 22

接受的答案对我不起作用,我按照本教程取得了成功.

基本上:

<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>
Run Code Online (Sandbox Code Playgroud)

  • 您还可以添加`mute:1`作为额外的'playerVar`,然后不需要`onReady`事件.一定要在`autohide:0`后添加一个逗号,并注意你不能使用`mute:0`,因为那将被视为'spammy'.另请注意,一旦您在刷新页面时明确静音视频,它仍然会被静音. (3认同)

小智 11

这很简单.只需将mute = 1添加到iframe的src参数即可.

例:

__CODE__