Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding additional parameters to the yt.player object from 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
                }
            }
        }
    });
}

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?

like image 637
Himmators Avatar asked Oct 08 '13 07:10

Himmators


People also ask

How do you get a YouTube embed code?

On a computer, go to the YouTube video or playlist you want to embed. From the list of Share options, click Embed. From the box that appears, copy the HTML code. Paste the code into your website HTML.

Does Rel 0 still work?

YouTube changed the rel=0 parameter as of September 2018 so that it no longer fully disables related videos. However, you can work around this using the YouTube Player API to show custom HTML instead of related videos.


1 Answers

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...

like image 110
codebreaker Avatar answered Oct 21 '22 08:10

codebreaker