8

Initially the video is hidden. When you click the image with ID 3, the video is visible. I put a button with ID close_video that will hide player. The problem is it's still running video after you click the button. How do I pause the video?

The code is:

<div id="video" class="popup-video">
  <div class="video">
    <div class="close_video" id="close_video">
    </div>
    <video id="id_video" width="400" height="257" controls="controls" preload="auto">
      <source src="{$content_dir}themes/trendy/video/Wildlife.mp4" type="video/mp4"/>     
    </video>                         
  </div>
</div>  

<script>
  $(document).ready(function(){
    $('#3').click(function(){
      $("#video").removeClass("popup-video").addClass("popup-video-show");
    });
  });
</script>
<script>
  $(document).ready(function(){
    $('#close_video').click(function(){
      $("#video").removeClass("popup-video-show").addClass("popup-video");
    });
  });
</script>

I also tried this:

<script>
  $(document).ready(function(){
    $('#close_video').click(function(){
      $("#video").removeClass("popup-video-show").addClass("popup-video");
      document.getElementById('id_video').pause();
      // and $("#id_video").pause();
    });
  });
</script>

Still no effect. The video disappears, but is still running.

Matthew Beckman
  • 1,702
  • 2
  • 16
  • 28
marius
  • 219
  • 1
  • 2
  • 10
  • I just googled your title and found the following topic : http://stackoverflow.com/questions/4155329/how-to-pause-a-html5-video-on-an-event – Brewal Apr 24 '13 at 14:12
  • You could use: `$("#id_video").gt(0).pause();` – Joe Apr 24 '13 at 14:15

3 Answers3

14

When using jQuery, you'll need to use 'get' first:

$('#videoId').get(0).pause()
Dan Esparza
  • 28,047
  • 29
  • 99
  • 127
1

When working with HTML5, use:

document.getElementById(\"movie_player\").click()

It works for me.

Milo
  • 3,365
  • 9
  • 30
  • 44
0

Normally you only need to click on the video to pause/play it.

Instead of using the pause() try to use the click()