【问题标题】:pause youtube video on next slide using cycle plugin使用循环插件在下一张幻灯片上暂停 youtube 视频
【发布时间】:2013-07-18 16:20:50
【问题描述】:

我在幻灯片中嵌入了一个 YouTube 视频(使用 Cycle Plugin 的 MaxImage),一旦用户单击下一张幻灯片,我就会尝试暂停该视频。 HTML5 视频有一个内置功能,但我只是不确定如何为 YouTube 做同样的事情。谢谢!

注意之前和之后的功能..

$(function(){
$('#maximage').maximage({
    cycleOptions: {
        fx: 'fade',
        speed: 600,
        timeout: 0,
        prev: '.prev',
        next: '.next',
        pause: 1,
        before: function(last,current){
            if(!$.browser.msie){
                // Start HTML5 video when you arrive
                if($(current).find('video').length > 0) $(current).find('video')[0].play();
                }
            },
        after: function(last,current){
            if(!$.browser.msie){
                // Pauses HTML5 video when you leave it
                if($(last).find('video').length > 0) $(last).find('video')[0].pause();
            }
        },    

        onFirstImageLoaded: function(){
        jQuery('#loader').hide();
        jQuery('#maximage').fadeIn(200);
    }
});         
});

【问题讨论】:

标签: jquery youtube slideshow jquery-cycle


【解决方案1】:

您需要使用iFrame API,否则由于跨域政策,您无法与视频互动:

var player;
function onYouTubeIframeAPIReady() {
  player = new YT.Player('player', {
    height: '390',
    width: '640',
    videoId: 'M7lc1UVf-VE',
    events: {
      'onReady': onPlayerReady,
      'onStateChange': onPlayerStateChange
    }
  });
}
$('#maximage').maximage({
    cycleOptions: {
        fx: 'fade',
        speed: 600,
        timeout: 0,
        prev: '.prev',
        next: '.next',
        pause: 1,
        before: function(last,current){
            if(player != null) player.playVideo()
        },
        after: function(last,current){
            if(player != null) player.pauseVideo()
        },    

        onFirstImageLoaded: function(){
        jQuery('#loader').hide();
        jQuery('#maximage').fadeIn(200);
    }
});     

【讨论】:

  • 我通读了 API 文档并尝试了您的代码,但肯定有问题。我的幻灯片拒绝加载。也许为时已晚或其他什么..
  • 您可能需要将 maximage 调用移动到 onPlayerReady 函数中,以确保仅在加载 youtube 剪辑时对其进行初始化
  • 成功了!只需要以不同的方式连接播放器。还有一件事,因为它在转到下一张幻灯片时会暂停,但是当返回到视频时,它会播放一秒钟然后再次暂停。打嗝。有没有办法在导航回视频时恢复视频?对不起,我很痛苦。
猜你喜欢
  • 2019-08-30
  • 2012-07-02
  • 1970-01-01
  • 2017-10-08
  • 2015-02-14
  • 1970-01-01
  • 1970-01-01
  • 2019-12-06
  • 2014-10-05
相关资源
最近更新 更多