I hacked up a quick snippet of Javascript that interacts with the Flowplayer Player
and Clip
objects to determine the video progress.
var videoProgressInterval;
flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.15.swf");
flowplayer("player").onStart(startVideoProgressChecking);
flowplayer("player").onResume(startVideoProgressChecking);
flowplayer("player").onStop(stopVideoProgressChecking);
flowplayer("player").onPause(stopVideoProgressChecking);
flowplayer("player").onFinish(stopVideoProgressChecking);
function startVideoProgressChecking() {
videoProgressInterval = setInterval(checkVideoProgress, 1000);
videoProgressInterval();
}
function stopVideoProgressChecking() {
clearInterval(videoProgressInterval);
}
function checkVideoProgress() {
var time_completed = flowplayer("player").getTime();
var total_time = flowplayer("player").getClip().fullDuration;
var percent_done = Math.floor((time_completed / total_time) * 100);
console.log(percent_done + "% of video done");
}
You can see a demo on JSFiddle.
It registers event handles for the start
and resume
events of the player. Once video playback has begun, it registers an interval which runs every second (feel free to modify this to run more often). The interval calls checkVideoProgress()
every time it gets executed which then gets the current playback time and total duration from the Clip
object to calculate the progress.
Additionally, an event handler is also registered for stop
, pause
and finish
events to clear the interval once the video has been paused/stopped.