If you have a (global) variable somewhere that tracks time, you can also use a global variable to hold the last time you updated the global time tracking variable, and at the body unload event ask the time again and subtract the two. Now you know the time until the user left the page. For example:
var gTotalTime=0;
var gLastTime, gPlaying;
...
onPause:function() {
gTotalTime += (your calculation);
gLastTime= new Date();
gPlaying= false;
}
...
function exit(){
if (gPlaying) gTotalTime += (new Date() - gLastDate);
}
...
<body onUnload="exit()">