Hello guys I want to store the duration of the video played when user pauses the video. Which video is in the <video src="">
tag
Asked
Active
Viewed 970 times
-1

Aniket Salunke
- 3
- 3
-
1In the interest of content quality, Stack Overflow doesn't permit duplication of questions which have been asked/answered here previously. In the future, please use the search function or your preferred search engine to research your inquiry before posting here. This is a duplicate of https://stackoverflow.com/questions/6380956/current-duration-time-of-html5-video – esqew Jun 21 '21 at 15:29
1 Answers
1
We can easily get the duration of a video using js. Using the onpause event listener, we can then use currentTime
to get the current time of the video. Here's an example of the usage:
var video = document.getElementById("video");
var time = document.getElementById("time");
video.addEventListener("pause", timev);
function timev() {
var curtime = video.currentTime;
time.innerHTML = curtime;
}
<video id="video" width="320" height="240" src="https://www.w3schools.com/html/movie.mp4" controls></video><br>
<span id="time">0.0</span>
This just calls the function timev()
on the video pause, and gets the time and updates the counter. In your question you also ask
I want to store the duration of the video played when user pauses the video.
If you mean store it using javascript as a variable, the stored duration is the variable var curtime
. If you want to save it and remember it even when the user reloads the site, you can use a database or localstorage.

John Doe
- 512
- 1
- 5
- 17