2014-01-31 197 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 
      } 
     } 
    }; 

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