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?
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.
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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With