Jek Jek - 3 months ago 6x
Javascript Question

jQuery get where the video is currently at

So I am making a streaming website and I wanted the user to be able to resume where they were last at, just by doing

requests every 10 seconds to send to the DataBase where the user is at, but I wanted to know what the method for getting where the current viewer is actually at?

An example is a
function that when applied to a video tag possibly can return what
the user is sitting on then set that as a variable.



In your timer loop you would want to call

var curTime = $("#videoID").text(currentTime);


var curTime = document.getElementById("videoID").currentTime;

which will return the current time in seconds (first uses jQuery, second plain JavaScript) and then save that to your database.

So, something like:

setTimeout(savetime, 10000)
function savetime() {
    var curTime = document.getElementById("videoID").currentTime;
    // save curTime to a cookie or remote database via ajax call