8

I have a tag in my html code with a locally stored video in it (not a link from youtube). I know there is a way to play/pause the video from javascript by using .pause() and .play(). Lets say I have a button that I would like to reset the video (skip to beginning). Is there a function for that in javascript/ jquery? If not then how can I achieve this?

Thanks to everyone in advance.

John Smith
  • 851
  • 2
  • 10
  • 22
  • Possible duplicate of [HTML5 video javascript controls - restart video](http://stackoverflow.com/questions/8402158/html5-video-javascript-controls-restart-video) – Yosvel Quintero Aug 23 '16 at 10:27

5 Answers5

10

You can use currentTime property as follow

var vid = document.getElementById("myVideo");
vid.currentTime = 0;
Divyesh Savaliya
  • 2,692
  • 2
  • 18
  • 37
4

You can use:

var video = document.getElementById('vidId');
video.pause();
video.currentTime = 0;
video.load();
2

You can alternatively parse the video again and then play the video it looks like this:

document.getElementById("videoid").src = "Your source file"
document.getElementById("videoid").play()
0

you can use..

var video = document.getElementById("myVideo");
video.load();

or

video.currentTime = 0; // sometime it will not work when videos are too long. 
Sarath
  • 2,318
  • 1
  • 12
  • 24
0

I could NOT get any of the above options to work and it would seem that the Video.js library has changed over time. The code that worked for me to get the video to restart from the beginning was simply:

var video = document.getElementById("myVideoTagId");
video.currentTime(0);

In the above code, calling the "currentTime()" method with a parameter value of 0 (zero) sets the time back to the beginning of the current video. The parameter for the "currentTime()" method can be used to set the current time of the video playback (in seconds) to any value valid for that video.

GeoffreyG
  • 99
  • 6