How to Autostart Youtube VIDEO with Low Volume (iframe)

二次信任 提交于 2021-02-19 08:35:08

问题


This is the iframe I create to autostart a video (music, mostly) in my blog :

< iframe width="140" height="105" src="https://www.youtube.com/embed/tGzl_AB4poI?rel=0&amp;showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>

It's all perfect. The only problem is the Audio, because the Volume is too high and I would decrease it- So I added this part on my code : "&player.setVolume(5)"

The final code, then, is this one:

< iframe width="140" height="105" src="https://www.youtube.com/embed/tGzl_AB4poI?rel=0&amp;showinfo=0&autoplay=1&player.setVolume(5)" frameborder="0" allowfullscreen></iframe>

The problem is that it wont works and the Volume is still the deafault one- (but the code still works with autoplay and all other pref).

What is going wrong?


回答1:


In IFrame API reference, you can use player.setVolume() to set the volume after the player is ready.

If you want to control the volume, you have to write some code in Javascript:

function onYouTubeIframeAPIReady() {
  // iframeId parameter should match your Iframe's id attribute
  var player = new YT.Player('iframeId', {
    width: 140,
    height: 105,
    videoId: 'tGzl_AB4poI',
    events: {
      'onReady': function (event) {
        event.target.setVolume(0);
        event.target.playVideo();
      }
    }
  });
}


来源:https://stackoverflow.com/questions/37244505/how-to-autostart-youtube-video-with-low-volume-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!