timestamps for video paused and restarted | XM Community
Skip to main content
Hello- Right now, I have javascript that gives me a timestamp for when a video (from my library) is started. I also have a timestamp for when my respondant reacts to the video, the person clicks a button below the video and that timestamp is recorded.



I need to know if they pause the video and restart it. I also need those events timestamped.



Any help with the javascript would be much appreciated. I am very new to javascript, and the community has been of great help!
It would be great to record the timestamp of each pause and restart.
Here's what we used:



Qualtrics.SurveyEngine.addOnload(function()



{



/*Place your JavaScript here to run when the page is unloaded*/



});





Qualtrics.SurveyEngine.addOnReady(function()

{

pauseTimestamp = null;

playTimestamp = null;



pauses = [];

plays = [];

playCount = 0;

pauseCount = 0;



jQuery("video").on('play', function() {

playCount++;

playTimestamp = Date.now();

if (pauseTimestamp) {

pauses.push(playTimestamp - pauseTimestamp);

}

Qualtrics.SurveyEngine.setEmbeddedData('playCount', playCount);

Qualtrics.SurveyEngine.setEmbeddedData('pauses', pauses.join(";"));

});



jQuery("video").on('pause', function() {

pauseCount++;

pauseTimestamp = Date.now();

plays.push(pauseTimestamp - playTimestamp);

Qualtrics.SurveyEngine.setEmbeddedData('pauseCount', pauseCount);

Qualtrics.SurveyEngine.setEmbeddedData('plays', plays.join(";"));

});



var s='';



jQuery("video").on('play', function() {



if(s==''){



s= Date.now();



Qualtrics.SurveyEngine.setEmbeddedData( 'Vid1Start', s);



}



});



var z='';



jQuery("video").on('pause', function() {



if(z==''){



z= Date.now();



Qualtrics.SurveyEngine.setEmbeddedData( 'Vid1Pause', z);



}



});





});



Qualtrics.SurveyEngine.addOnUnload(function()



{

if (playCount > pauseCount) {

plays.push(Date.now() - playTimestamp);

Qualtrics.SurveyEngine.setEmbeddedData('plays', plays.join(";"));

} else if (pauseCount) {

pauses.push(Date.now() - pauseTimestamp);

Qualtrics.SurveyEngine.setEmbeddedData('pauses', pauses.join(";"));

}

});

Leave a Reply