【发布时间】:2014-03-12 11:58:56
【问题描述】:
我注意到官方的 Fancybox youtube 实现 JSfiddle 在 iO 上不起作用,有什么想法吗?
http://jsfiddle.net/M78zz/show/
// Fires whenever a player has finished loading
function onPlayerReady(event) {
event.target.playVideo();
}
// Fires when the player's state changes.
function onPlayerStateChange(event) {
// Go to the next video after the current one is finished playing
if (event.data === 0) {
$.fancybox.next();
}
}
// The API will call this function when the page has finished downloading the JavaScript for the player API
function onYouTubePlayerAPIReady() {
// Initialise the fancyBox after the DOM is loaded
$(document).ready(function() {
$(".fancybox")
.attr('rel', 'gallery')
.fancybox({
openEffect : 'none',
closeEffect : 'none',
nextEffect : 'none',
prevEffect : 'none',
padding : 0,
margin : 50,
beforeShow : function() {
// Find the iframe ID
var id = $.fancybox.inner.find('iframe').attr('id');
// Create video player object and add event listeners
var player = new YT.Player(id, {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
});
});
}
fancybox 打开,youtube 视频加载,然后看起来要开始播放了,然后我就黑屏了。这在 iPhone 和 iPad 上都会发生。
谁能帮忙?
【问题讨论】:
-
根据您的评论,我做了并编辑了我的答案,解释了为什么 stackoverflow.com/a/20863405/1055987 特别是,iOS 上的 youtube 似乎不喜欢
event.target.playVideo();,它在视频转换为 HTML5 格式之前运行
标签: jquery youtube fancybox youtube-api fancybox-2