jQuery 如何在没有控件的情况下在 video.js 上暂停视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18726676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:20:08  来源:igfitidea点击:

How to pause video on video.js without controls

javascriptjqueryjavascript-eventsvideo.js

提问by user2726883

I'm using video.js. Here's how I have implemented it.

我正在使用 video.js。这是我如何实施它。

<video id="example_video_1" class="video-js vjs-default-skin" loop preload="auto" width="530" height="530" poster="<?php echo $iurl; ?>" autoplay>
<source src="<?php echo $vurl; ?>" type='video/mp4' />
</video>

As you have noticed, the controls are disabled. But I would like to pause this video when it's clicked. Can someone tell me how I can do that.

如您所见,控件已禁用。但是我想在点击这个视频时暂停它。有人可以告诉我如何做到这一点。

回答by heeya

According to the documentation here (https://github.com/videojs/video.js/blob/master/docs/api.md), the following javascript should work:

根据此处的文档(https://github.com/videojs/video.js/blob/master/docs/api.md),以下 javascript 应该可以工作:

HTML

HTML

<video id="example_video_1" onclick="togglePause()" class="video-js vjs-default-skin" loop preload="auto" width="530" height="530" poster="<?php echo $iurl; ?>" autoplay>
<source src="<?php echo $vurl; ?>" type='video/mp4' />
</video>

Javascript

Javascript

var myPlayer = videojs("example_video_1");
togglePause = function(){
  if (myPlayer.paused()) {
    myPlayer.play();
  }
  else {
    myPlayer.pause();
  }
}

After being paused, I assumed the video should resume playing? jsFiddle working example: http://jsfiddle.net/fR2Xs/

暂停后,我认为视频应该继续播放?jsFiddle 工作示例:http: //jsfiddle.net/fR2Xs/

回答by Sirius Clarke

Another way of doing it is by enabling the controls and setting their display value to none. This way you can pause the video and controls are not visible.

另一种方法是启用控件并将其显示值设置为无。这样您就可以暂停视频并且控件不可见。

.vjs-control-bar, .vjs-big-play-button {
   display: none !important;
}