简体   繁体   English

使用 Froogaloop JavaScript 和 jQuery 重新启动 Vimeo iFrame

[英]Restart Vimeo iFrame with Froogaloop JavaScript and jQuery

My page dynamically launches one of several Vimeo iFrame embedded videos and I'm using jQuery to fade them in/out and start/stop.我的页面动态启动几个 Vimeo iFrame 嵌入视频之一,我正在使用 jQuery 将它们淡入/淡出和开始/停止。 Right now, my close function hides the video and subsequently pauses it.现在,我的关闭功能会隐藏视频并随后暂停它。 If you bring up the same video after its been hidden it begins from where it was paused the time before.如果您在隐藏后调出相同的视频,它会从前一次暂停的位置开始。 I'd like it to restart.我希望它重新启动。 I can't figure out just the right action.我想不出正确的动作。 Some how "stop" and "restart" aren't options (how illogical is that? play/pause/stop).有些“停止”和“重新启动”不是选项(这有多不合逻辑?播放/暂停/停止)。

I'm linking to Vimeo's hosted version of Froogaloop JS and using jQuery to call the functions.我正在链接到 Vimeo 托管的 Froogaloop JS 版本并使用 jQuery 来调用这些函数。

Thanks!谢谢!

JavaScript: JavaScript:

$('#close, #underlay').click(function() {
    $('.vim, #close, #container, #underlay').fadeOut(400);
    var player=$f($('.vid:visible')[0]);
    player.api('pause');
});

When you have it fade in, you could seek the video to the beginning like this:当你淡入时,你可以像这样从头开始寻找视频:

player.api("seekTo", 0);
player.play();

要完全重新启动,我喜欢

player.api('unload')

I prefer a solution of persistently reseting all the videos and then pausing them.我更喜欢持续重置所有视频然后暂停它们的解决方案。 Next, play the current video that is being shown.接下来,播放正在显示的当前视频。

Below code can be optimized, but it gets the job done with no real drawbacks.下面的代码可以优化,但它可以完成工作而没有真正的缺点。

   function playCurrentVidPWA() {
      let allVids = document.getElementsByClassName('vimeo-player');
      let currentVideo = mySwiper.slides[mySwiper.activeIndex].querySelector('iframe');
   
      // Pause all videos
      if (allVids)
      {
         for (let i = 0; i < allVids.length; i++)
         {
            const iVid = allVids[i]
            let player = new Vimeo.Player(iVid);
            // Set the time of the video back to the begining
            player.setCurrentTime(0)
            // Pause the video for no frame-skip animations
            player.pause()
         }
      }
      // Play current slide video
      if(currentVideo)
      {
         let player = new Vimeo.Player(currentVideo);
         player.play()
      }
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM