Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pause video on video.js without controls

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

<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.

like image 584
user2726883 Avatar asked Sep 10 '13 18:09

user2726883


People also ask

How do you pause a video in HTML?

HTML Audio/Video DOM pause() Method The pause() method halts (pauses) the currently playing audio or video.

Can video JS play YouTube videos?

A <youtube-video> web component that allows you to easily play and control YouTube videos, powered by the YouTube IFrame Player API. In addition to simple rendering, videos can be played, stopped, paused, and more all with simple, native javascript.

Why is video duration NaN?

The Video duration property is a read-only property. The Video duration function returns “NaN” if no video is set whereas if the video is streamed and has no predefined length, it returns “Inf” (Infinity). Below program illustrates the Video duration Property : Example: Getting the length of a video.


2 Answers

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

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

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/

like image 63
neal Avatar answered Oct 16 '22 07:10

neal


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;
}
like image 27
Sirius Clarke Avatar answered Oct 16 '22 07:10

Sirius Clarke