Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
youtube iframe API在ipad和iphone上不起作用_Iphone_Ipad_Youtube Api_Youtube Javascript Api - Fatal编程技术网

youtube iframe API在ipad和iphone上不起作用

youtube iframe API在ipad和iphone上不起作用,iphone,ipad,youtube-api,youtube-javascript-api,Iphone,Ipad,Youtube Api,Youtube Javascript Api,我试图为幻灯片重新创建多个iframe示例。除iphone和ipad外,它在包括桌面safari在内的所有浏览器中都能完美运行 Js: var tag=document.createElement('script'); tag.src=”https://www.youtube.com/iframe_api"; var firstScriptTag=document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.inse

我试图为幻灯片重新创建多个iframe示例。除iphone和ipad外,它在包括桌面safari在内的所有浏览器中都能完美运行

Js:

var tag=document.createElement('script');
tag.src=”https://www.youtube.com/iframe_api";
var firstScriptTag=document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(标记,firstScriptTag);
var players={}
var YT_ready=(函数(){
var onReady_funcs=[],
api_isReady=假;
返回函数(func,b_之前){
如果(func==true){
api_isReady=真;
对于(变量i=0;i
HTML:


根据

autoplay、playVideo()和loadVideoById()等函数和参数不能在所有移动环境中工作

在你的
YTReady
功能中,你可以动态加载一段视频,这在iOS上是不可能的

您还可以尝试并尝试加载另一个id,您将看到它无法完成

你也应该检查一下

var tag = document.createElement('script');

tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

var players = {}

var YT_ready = (function() {
    var onReady_funcs = [],
        api_isReady = false;
    return function(func, b_before) {
        if (func === true) {
            api_isReady = true;
            for (var i = 0; i < onReady_funcs.length; i++) {
                // Removes the first func from the array, and execute func                                                                                                                     
                onReady_funcs.shift()();
            }
    }
        else if (typeof func == "function") {
            if (api_isReady) func();
            else onReady_funcs[b_before ? "unshift" : "push"](func);
        }
    }
})();


function onYouTubeIframeAPIReady() {
  jQuery(window).bind("load", function() {
    YT_ready(true);
  });
}

YT_ready(function() {
        var identifier = "v9d09JLBVRc";
            players[identifier] = new YT.Player(identifier, {
                events: {
                  'onReady': onPlayerReady,
                    "onStateChange": createYTEvent(identifier)
                }
            });
});

function onPlayerReady(event) {
  event.target.playVideo();
}

// Returns a function to enable multiple events                                                                                                                                                
function createYTEvent(identifier) {
    var player = players[identifier]; // Get cached player instance                                                                                                                            
    return function (event) {
      console.log(event.data);
    }
}
<div id="yt-container">
  <iframe width="640" height="480" id="v9d09JLBVRc" class="media-youtube-player" src="//www.youtube.com/embed/v9d09JLBVRc?enablejsapi=1&autoplay=0" frameborder="0" allowfullscreen></iframe>
</div>