1 html javascript youtube iframe jquery
这是我创建的 iframe,用于在我的博客中自动启动视频(主要是音乐):
< iframe width="140" height="105" src="https://www.youtube.com/embed/tGzl_AB4poI?rel=0&showinfo=0&autoplay=1" frameborder="0" allowfullscreen></iframe>
Run Code Online (Sandbox Code Playgroud)
这一切都很完美。唯一的问题是音频,因为音量太高,我会降低它 - 所以我在我的代码中添加了这部分:"&player.setVolume(5)"
那么,最终的代码是这样的:
< 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>
Run Code Online (Sandbox Code Playgroud)
问题是它不起作用,而且 Volume 仍然是默认的-(但代码仍然适用于自动播放和所有其他偏好)。
出了什么问题?
在IFrame API 参考 中,您可以使用player.setVolume()在播放器准备好后设置音量。
如果你想控制音量,你必须用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();
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7393 次 |
| 最近记录: |