10

我知道这是不可取的。但是仍然需要实现这个功能。尝试了从寻求,寻求媒体控制器的一切。没有任何效果。是否有任何外部库可以禁用搜索。如果一些关于如何使用自定义控件的指示会很有帮助。

4

8 回答 8

34

这个问题很老但仍然相关,所以这是我的解决方案:

var video = document.getElementById('video');
var supposedCurrentTime = 0;
video.addEventListener('timeupdate', function() {
  if (!video.seeking) {
        supposedCurrentTime = video.currentTime;
  }
});
// prevent user from seeking
video.addEventListener('seeking', function() {
  // guard agains infinite recursion:
  // user seeks, seeking is fired, currentTime is modified, seeking is fired, current time is modified, ....
  var delta = video.currentTime - supposedCurrentTime;
  if (Math.abs(delta) > 0.01) {
    console.log("Seeking is disabled");
    video.currentTime = supposedCurrentTime;
  }
});
// delete the following event handler if rewind is not required
video.addEventListener('ended', function() {
  // reset state in order to allow for rewind
    supposedCurrentTime = 0;
});

提琴手

它与玩家无关,即使在显示默认控件时也能正常工作,即使在控制台中输入代码也无法绕过。

于 2015-12-20T18:26:59.863 回答
3

扩展来自@svetlin-mladenov 的答案,您可以执行以下操作以防止用户寻找尚未观看的视频的任何部分。这也将允许用户倒带并寻找之前已经观看过的视频的任何部分。

var timeTracking = {
                    watchedTime: 0,
                    currentTime: 0
                };
                var lastUpdated = 'currentTime';

                video.addEventListener('timeupdate', function () {
                    if (!video.seeking) {
                        if (video.currentTime > timeTracking.watchedTime) {
                            timeTracking.watchedTime = video.currentTime;
                            lastUpdated = 'watchedTime';
                        }
                        //tracking time updated  after user rewinds
                        else {
                            timeTracking.currentTime = video.currentTime;
                            lastUpdated = 'currentTime';
                        }
                    }


                });
                // prevent user from seeking
                video.addEventListener('seeking', function () {
                    // guard against infinite recursion:
                    // user seeks, seeking is fired, currentTime is modified, seeking is fired, current time is modified, ....
                    var delta = video.currentTime - timeTracking.watchedTime;
                    if (delta > 0) {
                        video.pause();
                        //play back from where the user started seeking after rewind or without rewind
                        video.currentTime = timeTracking[lastUpdated];
                        video.play();
                    }
                });
于 2016-09-28T18:15:44.353 回答
0

您可以使用像video.js这样的 HTML5 视频播放器并使用 CSS 来隐藏搜索栏。

或者您可以为 HTML5 视频构建自己的控件

此外,您正在寻找的事件是“寻找”。如(使用新的 jquery 事件绑定):

$(myVideoElement).on('seeking', function(){
  // do something to stop seeking
})
于 2012-08-10T17:11:30.933 回答
0
<!DOCTYPE html> 
<html> 
<body> 

<video controls onseeking="myFunction(this.currentTime)">
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

<p>Video courtesy of <a href="http://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

<script>
var currentpos = 0;

function myFunction(time) {
    if(time > currentpos) {
      video.currentTime = currentpos;
    }
}

var video = document.getElementsByTagName('video')[0];

function getpos(){
  currentpos = video.currentTime;
}
onesecond = setInterval('getpos()', 1000);
</script>

</body> 
</html>

Did the trick for me :)
于 2015-03-16T15:23:50.390 回答
0
var supposedCurrentTime = 0;

$("video").on("timeupdate", function() {

    if (!this.seeking) {
        supposedCurrentTime = this.currentTime;
    }
});
// prevent user from seeking
$("video").on('seeking', function() {
    // guard agains infinite recursion:
    // user seeks, seeking is fired, currentTime is modified, seeking is fired, current time is modified, ....
    var delta = this.currentTime - supposedCurrentTime;

    if (Math.abs(delta) > 0.01) {
        //console.log("Seeking is disabled");
        this.currentTime = supposedCurrentTime;
    }

});

$("video").on("ended", function() {
    // reset state in order to allow for rewind
    supposedCurrentTime = 0;
});
于 2019-07-25T05:08:14.193 回答
0

要隐藏所有视频控件,请使用此 -

document.getElementById("myVideo").controls = false;
于 2020-06-22T14:26:55.293 回答
0

也许它可以帮助某人,我用这种方式来删除所有的进度控制回调。

player.controlBar.progressControl.off();
player.controlBar.progressControl.seekBar.off();
于 2021-09-28T13:30:03.533 回答
-1

使用 video js 作为我的视频播放器,而不是普通的 HTML5 版本:

.vjs-default-skin .vjs-progress-holder {
  height: 100%;
  pointer-events: none;
}
于 2015-07-22T13:58:41.577 回答