问题描述:

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?

网友答案:

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() {
    var player;
    //This iframeId parameter needs to match your Iframe's id attribute
    player = new YT.Player('iframeId', {
        width: 140,
        height: 105,
        videoId: 'tGzl_AB4poI',
        events: {
            'onReady': onPlayerReady
        }
    });
}

function onPlayerReady(event) {
    event.target.setVolume(0);
    event.target.playVideo();
}
相关阅读:
Top