Reputation: 901
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.
Upvotes: 8
Views: 22100
Reputation: 99
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.
Upvotes: 0
Reputation:
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()
Upvotes: 2
Reputation: 2353
you can use..
var video = document.getElementById("myVideo");
video.load();
or
video.currentTime = 0; // sometime it will not work when videos are too long.
Upvotes: 0
Reputation: 659
You can use:
var video = document.getElementById('vidId');
video.pause();
video.currentTime = 0;
video.load();
Upvotes: 4
Reputation: 2730
You can use currentTime property as follow
var vid = document.getElementById("myVideo");
vid.currentTime = 0;
Upvotes: 10