There have been problems with the YouTube API in the last few days. The problem is that when embedding videos with the official API, it simply does not allow you to access the API. When you try to access the API, you get an error in the log (IOS), and if you try to play the video through the API, the video will go out. If you download it through the API, but you do not use the API, the user can play the video by clicking.
The problem persists in the following browsers:
IOS 7 Safari on iPad and iPhone iOS 7 Chrome on iPad and iPhone Android 4 Chrome
(My play button uses the API to play the video and create an error) JSfiddle: http://jsfiddle.net/frdd8nvr/6/
Error message:
Unable to post message to https://www.youtube.com. Recipient has origin http://fiddle.jshell.net. postMessage[native code]:0 Jwww-widgetapi.js:26:357 Nwww-widgetapi.js:25 (anonymous function)[native code]:0 html5player.js:1201:97 Blocked a frame with origin "https://www.youtube.com" from accessing a frame with origin "http://jsfiddle.net". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.
Some debugging info:
As I can see, the API creates an iframe on the site. Src is once http and sometimes https.
http://www.youtube.com/embed/ZPy9VCovVME?enablejsapi=1&origin=http%3A%2F%2Ffiddle.jshell.net&autoplay=0&modestbranding=1&wmode=opaque&forceSSL=false
My test showed that in most cases, YouTube servers are simply LOCATION: https: // ... a request for https-url, but about 10% they served an HTTP request with relevant content.
I think the problem is with forced https, but I could not find a solution. Have you experienced the same thing? Do you have any solution to this problem? Is this a YouTube bug?
My test code is:
<div id="myvideo"></div> <button id="play-button">Play</button>
JS:
var tag = document.createElement("script"); tag.src = "//www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName("script")[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); onYouTubeIframeAPIReady = function () { var vars = { enablejsapi: 1, origin: window.location.protocol + "//" + window.location.host, autoplay: 0, modestbranding: 1, wmode: "opaque", forceSSL: false }; if (+(navigator.platform.toUpperCase().indexOf('MAC') >= 0 && navigator.userAgent.search("Firefox") > -1)){ vars.html5 = 1; } var playerobj = new YT.Player('myvideo', { videoId: 'ZPy9VCovVME', wmode: 'opaque', playerVars: vars, events: { onReady: function(){ $('#play-button').on('click', function(){ playerobj.playVideo(); });