如何以低音量(iframe)自动启动Youtube VIDEO [英] How to Autostart Youtube VIDEO with Low Volume (iframe)
问题描述
这是我创建的iframe,用于自动启动博客中的视频(主要是音乐):
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&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>
一切都很完美.唯一的问题是音频,因为音量太高,我会降低音量-所以我在代码中添加了这部分:& player.setVolume(5)"
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&showinfo=0&autoplay=1&player.setVolume(5)" frameborder="0" allowfullscreen></iframe>
问题在于它无法正常工作,而且Volume仍然是默认的-(但是代码仍可与自动播放和所有其他偏好一起使用).
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).
出了什么问题?
推荐答案
在 IFrame API参考,您可以使用 player.setVolume()设置播放器之后的音量准备好了.
In IFrame API reference, you can use player.setVolume() to set the volume after the player is ready.
如果要控制音量,则必须使用Javascript编写一些代码:
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();
}
}
});
}
这篇关于如何以低音量(iframe)自动启动Youtube VIDEO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!