2017-06-04 42 views
0

我已经尝试了很多指南,并阅读了很多关于这个问题的答案,仍然没有设法解决这个问题。如何将我的YouTube嵌入式视频静音? P.s.我是编码的新手,对SOF来说是新手,如果我做了一些可怕的错误,请原谅我。静音video-bg不工作

<div class="video-bg embed-responsive embed-responsive-16by9"> 

<iframe class="embed-responsive-item" width="560" height="315" 
src="https://www.youtube.com/embed/ArGfDo1xQuM?rel=0&controls=0&showinfo=0&frameborder=0&autoplay=1&loop=1&playlist=eXadofBB7hM" frameborder="0" allowfullscreen></iframe> 

</div> 
+0

据我所知,没有办法使'iframe'元素静音。你可以下载视频并将其作为video元素的来源吗? –

+0

可能的重复[如何自动播放Youtube视频(IFrame API)静音?](https://stackoverflow.com/questions/8869372/how-do-i-automatically-play-a-youtube-video-iframe -api-muted) – mx0

+0

@JonathanBartlett我现在正在下载,这将需要一段时间,一定会尝试这种方式,并希望找到解决方案!我会让你更新 –

回答

0

您必须使用iframe_api。在IFRAME SRC属性你必须添加enablejsapi=1,也IFRAMEID属性与YT.Player实例连接它。然后使用此JavaScript来控制电影播放。

<script src='http://www.youtube.com/iframe_api'></script> 
<script> 
    var player; 
    function onYouTubeIframeAPIReady() { 
     player = new YT.Player('playerId', { 
      events: { 
       onReady:onPlayerReady 
       } 
      } 
     ) 
    } 
    function onPlayerReady(event) { 
     player.mute(); 
     player.setVolume(0); 
     player.playVideo(); 
    } 
</script> 


<div class="video-bg embed-responsive embed-responsive-16by9"> 

<iframe id='playerId' class="embed-responsive-item" width="560" height="315" 
src="https://www.youtube.com/embed/ArGfDo1xQuM?rel=0&controls=0&showinfo=0&frameborder=0&autoplay=1&loop=1&playlist=eXadofBB7hM&enablejsapi=1" frameborder="0" allowfullscreen></iframe> 

</div> 
+0

非常感谢!你节省了我的一天,我很高兴现在知道它是如何工作的! @ MX0 –