Fancybox YouTube无法在iPad或iPhone上运行

时间:2014-02-13 14:32:11

标签: jquery youtube fancybox youtube-api fancybox-2

我注意到官方的Fancybox youtube实现JSfiddle不适用于iOs,任何想法为什么?

http://jsfiddle.net/M78zz

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

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

这个问题似乎提出了很多,而且你的问题很可能是因为在Mobile Safari中,javascript被禁止自动播放或以编程方式开始播放标签中的任何内容(因为有没有闪光,是YouTube如何在那里提供视频)。相反,Mobile Safari要求用户必须启动播放(可能是因为用户不打算使用细胞数据而不打算)。

因此,如果fancybox依赖于程序化播放(即event.target.playVideo()),则它与Mobile Safari不兼容。

More info

相关问题