John Smith
John Smith

Reputation: 901

restart html video with javascript

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

Answers (5)

GeoffreyG
GeoffreyG

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

user15253655
user15253655

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

Sarath Kumar
Sarath Kumar

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

Văn Tuấn Phạm
Văn Tuấn Phạm

Reputation: 659

You can use:

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

Upvotes: 4

Divyesh Savaliya
Divyesh Savaliya

Reputation: 2730

You can use currentTime property as follow

var vid = document.getElementById("myVideo");
vid.currentTime = 0;

Upvotes: 10

Related Questions