How to embed an autoplaying YouTube video in an iframe?

This works in Chrome but not Firefox 3.6 (warning: RickRoll video): <iframe width=”420″ height=”345″ src=”http://www.youtube.com/embed/oHg5SJYRHA0?autoplay=1″ frameborder=”0″ allowfullscreen></iframe> The JavaScript API for iframe embeds exists, but is still posted as an experimental feature. UPDATE: The iframe API is now fully supported and “Creating YT.Player objects – Example 2” shows how to set “autoplay” in JavaScript.

How to check if YouTube channel is streaming live

You can do this by using search.list and specifying the channel ID, setting the type to video, and setting eventType to live. For example, when I searched for: https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCXswCcAMb5bvEUIDEzXFGYg&type=video&eventType=live&key=[API_KEY] I got the following: { “kind”: “youtube#searchListResponse”, “etag”: “\”sGDdEsjSJ_SnACpEvVQ6MtTzkrI/gE5P_aKHWIIc6YSpRcOE57lf9oE\””, “pageInfo”: { “totalResults”: 1, “resultsPerPage”: 5 }, “items”: [ { “kind”: “youtube#searchResult”, “etag”: “\”sGDdEsjSJ_SnACpEvVQ6MtTzkrI/H-6Tm7-JewZC0-CW4ALwOiq9wjs\””, “id”: { “kind”: … Read more

Stop embedded youtube iframe?

Unfortunately these API’s evolve very fast. As of May 2015, the proposed solutions don’t work anymore, as the player object has no stopVideo method. A reliable solution is to be found in this page (1) and it works with an: <iframe id=”youtube_player” class=”yt_player_iframe” width=”640″ height=”360″ src=”http://www.youtube.com/embed/aHUBlv5_K8Y?enablejsapi=1&version=3&playerapiid=ytplayer” allowfullscreen=”true” allowscriptaccess=”always” frameborder=”0″></iframe> and the following JS/jQuery code: $(‘.yt_player_iframe’).each(function(){ … Read more

Why am I seeing an “origin is not allowed by Access-Control-Allow-Origin” error here? [duplicate]

Javascript is limited when making ajax requests outside of the current domain. Ex 1: your domain is example.com and you want to make a request to test.com => you cannot. Ex 2: your domain is example.com and you want to make a request to inner.example.com => you cannot. Ex 3: your domain is example.com:80 and … Read more

How to pause a YouTube player when hiding the iframe?

The easiest way to implement this behaviour is by calling the pauseVideo and playVideo methods, when necessary. Inspired by the result of my previous answer, I have written a pluginless function to achieve the desired behaviour. The only adjustments: I have added a function, toggleVideo I have added ?enablejsapi=1 to YouTube’s URL, to enable the … Read more

YouTube iframe player API – OnStateChange not firing

There was a temporary issue with the iFrame Player API (which was fixed in June 2013) that you can read about here: https://code.google.com/p/gdata-issues/issues/detail?id=4706 Jeff Posnick posted a temporary workaround here: http://jsfiddle.net/jeffposnick/yhWsG/3/ As a temporary fix, you just need to add the event listener within the onReady event: function onReady() { player.addEventListener(‘onStateChange’, function(e) { console.log(‘State is:’, … Read more

Failed to execute ‘postMessage’ on ‘DOMWindow’: https://www.youtube.com !== http://localhost:9000

I believe this is an issue with the target origin being https. I suspect it is because your iFrame url is using http instead of https. Try changing the url of the file you are trying to embed to be https. For instance: ‘//www.youtube.com/embed/’ + id + ‘?showinfo=0&enablejsapi=1&origin=http://localhost:9000’; to be: ‘https://www.youtube.com/embed/’ + id + ‘?showinfo=0&enablejsapi=1&origin=http://localhost:9000’;

Why am I seeing an “origin is not allowed by Access-Control-Allow-Origin” error here? [duplicate]

Javascript is limited when making ajax requests outside of the current domain. Ex 1: your domain is example.com and you want to make a request to test.com => you cannot. Ex 2: your domain is example.com and you want to make a request to inner.example.com => you cannot. Ex 3: your domain is example.com:80 and … Read more