videojs - 隐藏界面时如何暂停视频?

时间:2018-05-28 17:34:36

标签: html css html5 css3 video.js

问题:是否可以暂停使用video.js播放器自动播放的视频,而不显示视频控件?

我正在将video.js用于网站,并在访问该网站时自动运行该视频。

<video id="my-video" class="video-js" controls preload="auto" data-setup='{
    "controls": false,
    "loop": "true",
    "autoplay": true, 
    "preload": "true"
    }'>
<source src="vid/gh.mp4" type='video/mp4'>

我决定隐藏控件,因此您只能看到视频。

是否可以点击视频停止播放?

我意识到通过将控件设置为false,我隐藏了播放按钮,因此删除了暂停视频的选项。

我仍然处于一个非常基本的水平,所以我不知道这是否可能 - 但我很想知道是否有办法做到这一点!

非常感谢

1 个答案:

答案 0 :(得分:3)

You can try this:

<video width="320" height="240"  onclick="this.pause()" autoplay>
  <source src="{{asset('video/media_.mp4')}}" type="video/mp4">
Your browser does not support the video tag.
</video>

This will pause your video by clicking on the video. But if you want to play your video again then you need to use the following line in the place of onclick:

  onclick="this.paused ? this.play() : this.pause();"