最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Autostart Youtube VIDEO with Low Volume (iframe) - Stack Overflow

programmeradmin0浏览0评论

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

< iframe width="140" height="105" src=";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=";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?

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

< iframe width="140" height="105" src="https://www.youtube./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./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?

Share Improve this question edited May 15, 2016 at 23:37 Smittey 2,49010 gold badges29 silver badges35 bronze badges asked May 15, 2016 at 22:48 Francesco Di RedaFrancesco Di Reda 111 gold badge1 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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();
      }
    }
  });
}
发布评论

评论列表(0)

  1. 暂无评论