2014-07-16 129 views
0

我试图重新创建幻灯片的多个iframe示例detailed here。它可以在所有浏览器中完美运行,包括桌面Safari,除了iPhone和iPad。youtube iframe API不适用于ipad和iphone

http://codepen.io/lakshminp/pen/mepIB

JS:

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); 
    } 
} 

HTML:

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

回答

0

根据this

功能和参数,如自动播放,调用playVideo(),loadVideoBy Id()将无法在所有移动环境中工作

并在您的YTReady函数中,您可以动态加载视频,而且目前在iOS上不可能。

你也可以尝试YouTubeDemoPage并尝试加载另一个ID,你会发现它不能完成。

您还应该检查this

相关问题