Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Disable play/pause on click of video element? Start play only on click of BigPlayButton. #2444

Closed
VinaykumarNM opened this issue Aug 7, 2015 · 25 comments
Labels

Comments

@VinaykumarNM
Copy link

Hi,
I want to play/pause the video only when clicked on BigPlayButton not any other place of the video element.

I am referring libraries from -

<link href="https://vjs.zencdn.net/4.12/video-js.css" rel="stylesheet"></link>
<script src="https://vjs.zencdn.net/4.12/video.js"></script>

Please let me know how i can achieve this.

@heff
Copy link
Member

heff commented Aug 12, 2015

Why do you want only the big play button clickable? There's not a built in way to turn that off easily.

@heff heff added the question label Aug 12, 2015
@ozanmakes
Copy link

It would be nice to have this in scenarios like rtmp streams where you might want the video to keep playing in case of accidental clicks but still want the player controls to function. I've found some stackoverflow questions about removing click handler of video.js Flash player but none of the workarounds I've tried worked with the latest minified versions.

@gkatsev
Copy link
Member

gkatsev commented Nov 17, 2015

Probably the best way is to add this to your css:

.vjs-tech {
  pointer-events: none;
}

The downside is that this wont work in IE8.

@gkatsev
Copy link
Member

gkatsev commented Nov 17, 2015

Going to close this for now as it's unlikely we'll do anything in videojs about this.
However, we can continue the discussion here and if there is sufficient usecase, we can reopen to add such a feature beyond the workaround above.

@gkatsev gkatsev closed this as completed Nov 17, 2015
@ozanmakes
Copy link

.video-js.vjs-playing .vjs-tech {
  pointer-events: none;
}

I think this is good enough for our use case, thanks @gkatsev.

@gkatsev
Copy link
Member

gkatsev commented Nov 18, 2015

No problem.

@Yulisa-Chang
Copy link

Hi ,I would like to know if there is a method to disable the default video onclick play/pause method so that i could do some other thing when the video is clicked? Thanks very much!

@djmakwana
Copy link

Is there any way in latest version 5.10.4 to disable play/pause when there is a click on the video? I tried following but it doesn't work.

.video-js.vjs-playing .vjs-tech {
  pointer-events: none;
}

@zcoding
Copy link

zcoding commented Nov 28, 2016

This is not a good solution for me because i just want the "mouse left click" to be disabled.

@kudlohlavec
Copy link

Little update to this thread:

For me

.video-js.vjs-has-started .vjs-tech {
  pointer-events: none;
}

worked, however it doesnt work for Safari 11 and also none of the above mentioned css rules worked in Safari. Any ideas for Safari? (there is still option to attach play function into pause event but its not very nice solution)

@ryanmasuga
Copy link

Our use case is a client embedding a (Brightcove) video in a carousel (Slick) slide. We'd like the video to only start when clicking the Big Play Button (that's....whats it's for), because if they click anywhere on the video itself to drag and move to the next slide, the video starts, and continues playing offscreen (which is a separate issue).

@dkirilenko
Copy link

any updates?

@dkirilenko
Copy link

ok, I've found not elegant way to do this. I use videojs 7.5.5 . I've added additional code to videojs to handleTechClick_ function:

   _proto.handleTechClick_ = function handleTechClick_(event) {
      if (this.options_.disableVideoPlayPauseClick) {
        return
      }
     ...

Then init my player by:

videojs(videoEl, {
  disableVideoPlayPauseClick: true, // or don't use this option if you want use this feature
  ...

And it works for me

@lasersocks
Copy link

@dkirilenko Are you able to share any more information about this?

@chenxiaolong
Copy link

Another (hacky) workaround (in 7.7.3) is:

var player = videojs('foobar', ...);
player.player_.handleTechClick_ = function() {};

My use is case is just for a dumb personal site that plays an HLS live stream that fills up the entire page. I prefer accidental clicks to not pause the stream.

@dkirilenko
Copy link

@lasersocks Hmm :)

  1. Download videojs 7.5.5
  2. Open script and find _proto.handleTechClick_ = function handleTechClick_(event) { line
  3. Add
if (this.options_.disableVideoPlayPauseClick) {
  return
}
  1. After that you'll have possibility to add disableVideoPlayPauseClick to your player
    videojs(videoEl, { disableVideoPlayPauseClick: true })

I haven't idea what information you need more )

@dkirilenko
Copy link

@lasersocks see @chenxiaolong comment and try it, if you don't want to change script source.

In my case we use player in several places and as for me will be better just to pass additional option where we need

@dkirilenko
Copy link

@gkatsev I think we need to open task again :) So many people who wants to have such possibility without css hook

@CodyDunlap
Copy link

This is something that we need as well. Our use case is for syncing video playback across multiple browsers and only allowing a single user to control playback. We'd still like all instances to see progress and be able to select captions, etc. We're using this in angular via npm so manually editing the js file feels incredibly hacky and brittle. Currently, the only way to do this is for us to disable controls in videojs and provide our own playback controls.

@Rhovian
Copy link

Rhovian commented Jun 20, 2020

Please please please reopen task

@Nyceane
Copy link

Nyceane commented Jul 29, 2020

please reopen stack, i tried @dkirilenko's answer and it is not working..

@cabello
Copy link

cabello commented Oct 11, 2020

My use case is a live streaming video integrated with AWS IVS and once the user clicks play, I would like to not pause the stream due to accidental clicks on the whole video. The suggested CSS change worked on Chrome, looking for alternatives for all browsers.

Thank you for making and sharing video.js 💜

@IliaIdakiev
Copy link

@cabello You can put an absolute positioned div on top of the video. Just make sure that you select a proper z-index.

@ziddey
Copy link

ziddey commented Feb 20, 2021

const options = {}
function ready() {
    this.off(this.tech_, 'mouseup', this.handleTechClick_)
}
const player = videojs('player', options, ready)

ref:

this.off(this.tech_, 'mouseup', this.handleTechClick_);

@oxwazz
Copy link

oxwazz commented Jul 4, 2021

in my case, i try this;
player.el_.firstChild.style.pointerEvents = 'none'

thats worked fine

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests