How to stop video-js onclick event from pausing video

六眼飞鱼酱① 提交于 2019-12-06 03:30:30

问题


I have a simple JSFiddle here: http://jsfiddle.net/cvCWc/2/

The basic code looks like:

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();
});

I am trying to capture all click events on the video for future processing, but I don't want the video to pause when clicked. Any ideas?


回答1:


I found the answer for HTML5... but I don't get click events in the flash fallback. Updated 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();
});



回答2:


Just an alternative if someone drops to this. When you wanna bypass the stop play functionality when user clicks the stream(or view, whatever you call it), not the control bar, one can comment out somelines in videojs..

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
            }
        }
    };

Control bar will still work...



来源:https://stackoverflow.com/questions/21470677/how-to-stop-video-js-onclick-event-from-pausing-video

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