问题
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>
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>
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