2014-01-31 160 views
3

我有一个简单的jsfiddle这里:http://jsfiddle.net/cvCWc/2/如何停止视频的js onclick事件从暂停视频

基本的代码如下所示:

window.player = videojs("movie_container", { techOrder: ["html5", "slash"] }, function() { 
    videojs_player = this; 
    videojs_player.src({ src: "http://video-js.zencoder.com/oceans-clip.mp4", type: 'video/mp4'}) 

    videojs_player.on("click", function(event){ 
     event.preventDefault(); 
     alert('click'); 
    }); 

    videojs_player.play(); 
}); 

我试图捕捉视频中的所有点击事件以供将来处理,但我不希望视频在点击时暂停。有任何想法吗?

回答

7

我找到了HTML5的答案......但我没有在Flash后备中获得点击事件。已更新jsfdl:http://jsfiddle.net/cvCWc/3/

window.player = videojs("movie_container", { techOrder: ["html5", "flash"] }, function() { 
    videojs_player = this; 
    videojs_player.src({ src: "http://video-js.zencoder.com/oceans-clip.mp4", type: 'video/mp4'}) 
    videojs_player.off('click'); 
    videojs_player.on("click", function(event){ 
     event.preventDefault(); 
     console.log("click", event.clientX, event.clientY, videojs_player.currentTime()); 
    }); 

    videojs_player.play(); 
}); 
+0

要跟进这一点,我发现如果你设置Flash对象的wmode为透明,然后捕获mousedown事件,你会得到点击!请参阅:http://jsfiddle.net/cvCWc/4/ – DaKaZ

1

只要有人愿意选择此选项,就是另一种选择。当你想绕过当用户点击流(或视图,无论你怎么称呼它)停止玩游戏功能,而不是控制栏,可以在videojs注释掉somelines ..

Player.prototype.handleTechClick_ = function handleTechClick_(event) { 
     // We're using mousedown to detect clicks thanks to Flash, but mousedown 
     // will also be triggered with right-clicks, so we need to prevent that 
     if (event.button !== 0) return; 

     // When controls are disabled a click should not toggle playback because 
     // the click is considered a control 
     if (this.controls()) { 
      if (this.paused()) { 
       //this.play(); // COMMENTED OUT 
      } else { 
       //this.pause(); // COMMENTED OUT 
      } 
     } 
    }; 

控制栏仍然可以工作。 ..