Pause all Vimeo videos with API?

你离开我真会死。 提交于 2019-12-07 21:40:14

问题


I have hit a wall and cannot figure out how to make this work. With Vimeo's Advanced API I am pulling in all videos from an account with thumbnails. When clicking on a thumbnail the video is shown above and clicking on a different thumbnail hides the currently shown video. The problem is that the video continues to play even when it is hidden. I have spent a few hours looking at the API and I cannot get it to pause when hidden.

var iframe = $('.video')[0];

  $('.thumbnail a').click(function(e) {

  $f(iframe).api('pause');

  });

The above code pauses only the first video. If I change the number [0] to [1], then the second video pauses when you click on another thumbnail. Does anyone have any thoughts? I am using froogaloop in the above code.


回答1:


I used this with jQuery:

<script type="text/javascript" src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
<script type="text/javascript">// <![CDATA[
function pauseAll() {
    $('iframe[src*="vimeo.com"]').each(function () {
        $f(this).api('pause');
    });
}
// ]]></script>

use it on an onclick.

<a href="#" onclick="pauseAll(); return false;">pause all</a>



回答2:


You can use this code to pause all YouTube and Vimeo videos on the page:

$('iframe').each(function() {
  this.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
  this.contentWindow.postMessage('{"method":"pause","value":""}', '*');
});


来源:https://stackoverflow.com/questions/15654402/pause-all-vimeo-videos-with-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!