在页面上单击另一个视频时暂停jquery jPlayer

时间:2012-04-14 10:46:29

标签: jquery jplayer

我在所有页面上播放背景音乐(jPlayer),我需要在帖子或页面或侧边栏上点击/播放另一个嵌入视频时暂停它 虽然这段代码似乎不起作用:

<script>
//pauses jplayer
var selectors = [
        "iframe[src^='http://player.vimeo.com']", 
        "iframe[src^='http://www.youtube.com']", 
        "iframe[src^='https://www.youtube.com']", 
        "iframe[src^='http://www.kickstarter.com']", 
        "object", 
        "embed"
      ];
  $selectors.click(function() {
  $.jPlayer.pause();
});
</script>

什么可能是错的?

1 个答案:

答案 0 :(得分:1)

$(function() {
    // Find all videos
    var selectors = [
        "iframe[src^='http://player.vimeo.com']", 
        "iframe[src^='http://www.youtube.com']", 
        "iframe[src^='https://www.youtube.com']", 
        "iframe[src^='http://www.kickstarter.com']", 
        "object", 
        "embed"
      ];
        // The element that is fluid width
    var $allVideos = $(this).find(selectors.join(','));
    // Figure out and save aspect ratio for each video
        $allVideos.hover(function(){
            $.jPlayer.pause(); 
        });
});

适用于悬停 - 对于不同的玩家API,点击很复杂