Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Video pause and rewind

Is there any way to pause and rewind to 0s a HTML5 video? Or just simply stop?

I got a jQuery popup, so when someone clicks on it, the popup shows up and the video plays, and when you hit the close button the video pauses. So what I'm trying to do is that if you click again the button to show the popup the video begins in the start position (0 secs).

Thanks.

like image 880
Alejandro Ar Avatar asked Oct 21 '11 18:10

Alejandro Ar


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 we play video in HTML5?

With the introduction of HTML5, you can now place videos directly into the page itself. This makes it possible to have videos play on pages that are designed for mobile devices, as plugins like Adobe Flash Player don't work on Android or iOS. The HTML <video> element is used to embed video in web documents.

What is HTML5 video format?

HTML5 Video Format for Desktop and Mobile Streaming The HTML5 video format capabilities include three options to play: MP4, WebM, and Ogg. You should note that the Safari browser does not support Ogg, WebM is supported by only 58% of browsers, and MP4 is disabled by default in Firefox 24.


Video Answer


2 Answers

You can get a reference to your jquery video element upon opening it (or closing the popup) and pause it using pause(), and then set the "currentTime" property to 0 to go back to the beginning.

Here's a reference to the documentation for currentTime.

here's a code sample:

var mediaElement = document.getElementById("video"); 
mediaElement.pause(); 
mediaElement.currentTime = 0;
like image 62
Chris Ching Avatar answered Oct 19 '22 23:10

Chris Ching


To have a proper stop (pause & rewind) functionality you could do the following:

var video = document.getElementById('vidId');
// or video = $('.video-selector')[0];
video.pause();
video.currentTime = 0;
video.load();

Note: This is the only version that worked for me in chrome using nodejs (meteorjs) in the backend, serving webm & ogg files

like image 7
Matyas Avatar answered Oct 19 '22 22:10

Matyas