I am running a study where participants need to hear an imbedded audio clip once and then the page auto advances to the next question. Below is my current code. I had to do it this way because I wanted the page to advance after the audio ended but the built-in qualtrics auto advance option doesn't take into account the time it takes the page to load- basically I couldn't guess how long the page would take to load and I wanted the page to advance without delay.
I currently have 2 issues. 1) I want to be able to advance to the next page early and have the audio clip end (so that we can skip the audio clips when we are testing the survey). 2) the audio clips sometimes aren't playing if the survey has been open/inactive for a little bit.
I'm not sure where exactly problem 2 is coming from, but I have to assume it's from my current code. For more info, we have participants play a youtube video within the survey and that audio will work when the imbedded audio clips don't. I am not familiar with javascript, I found this code in another post.
Qualtrics.SurveyEngine.addOnload(function()
{
});
Qualtrics.SurveyEngine.addOnReady(function()
{
const audio = new Audio("https://tufts.qualtrics.com/CP/File.php?F=F_4SzAcwK3Vf9RolU");
var delay = 500;
audio.addEventListener('ended', (event) => {
setTimeout(function () {
jQuery("#NextButton").click();
}, delay);
});
audio.play();
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
});