从youtube向yt.player对象添加其他参数 [英] Adding additional parameters to the yt.player object from youtube

查看:423
本文介绍了从youtube向yt.player对象添加其他参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用yt.player启动youtube视频,如下所示:

I'm initiating a youtube video using yt.player like this:

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
                }
            }
        }
    });
}

使用嵌入代码添加视频时,我可以添加多个其他参数,例如:
controls = 0& modestbranding = 1& showinfo = 0& autoplay = 1

When adding a video using the embed-code, I can add a multitude of other parameters, like these: controls=0&modestbranding=1&showinfo=0&autoplay=1

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

When i try to add autoplay for example I tried this:

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
                }
            }
        }
    })

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

but it doesn't work. What am I doing wrong?

推荐答案

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
                }
            }
        }
    })

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

try this code and reply me on this...

这篇关于从youtube向yt.player对象添加其他参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆