Mediaelement.js - pause / play onclick for video?

What is the easiest way to add pause / play functionality by clicking anywhere on the video element, similar to most video players?

I tried:

$('video').click(function() { if($(this).paused){ $(this).play(); } else { $(this).pause(); } }); 

But he did not like the call to $ (this) .pause (). Any help is appreciated. Thanks.

DS

+4
source share
2 answers
  $(".mejs-mediaelement").click(function(){ if($(".mejs-overlay-play").css('display') == 'none'){ $('video').each(function(){this.player.pause()}); } }); 

just try it :)

+3
source
 $('video').click(function() { if(this.paused){ this.play(); } else { this.pause(); } }); 

But that will not work. You will want to place an invisible div (with an invisible PNG in it) above the video to receive click commands.

Or you can use a solution like http://videojs.com/

0
source

Source: https://habr.com/ru/post/1348154/


All Articles