Jek Jek - 4 months ago 9
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

AJAX
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
jQuery
function that when applied to a video tag possibly can return what
minute:second
the user is sitting on then set that as a variable.

Thanks.

Answer

In your timer loop you would want to call

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

or

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
}