从youtube向yt.player对象添加其他参数

时间:2013-10-08 07:01:49

标签: javascript youtube youtube-api youtube-javascript-api

我正在使用像这样的yt.player发布YouTube视频:

function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '720',
        width: '1280',
        html5: 0,
        videoId: 'i8IXMGHpGBk',
        events: {
            'onStateChange': function(e) {
                if (e.data == 0) {
                    //skrolla här
                }
            }
        }
    });
}

使用嵌入代码添加视频时,我可以添加许多其他参数,例如: 对照= 0&安培;适度品牌= 1&安培; showinfo = 0&安培;自动播放= 1

当我尝试添加自动播放时,我尝试了这个:

function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '720',
        width: '1280',
        html5: 0,
        videoId: 'i8IXMGHpGBk',
        autoplay: 1,
        events: {
            'onStateChange': function(e) {
                if (e.data == 0) {
                    //skrolla här
                }
            }
        }
    })

但它不起作用。我做错了什么?

1 个答案:

答案 0 :(得分:29)

function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '720',
        width: '1280',

        videoId: 'i8IXMGHpGBk',
        playerVars: { 'autoplay': 1, 'controls': 1,'autohide':1,'wmode':'opaque' },
        events: {
            'onStateChange': function(e) {
                if (e.data == 0) {
                    //skrolla här
                }
            }
        }
    })

试试这段代码并回复我......