Solved
Detect state change on youtube iframe
I need to embed a youtube video in our survey and I need to know when it finishes, as I want to display a question or next button after the video goes to completion. We can't use a timer as we are allowing people to pause the video (unless I can pause the timer?), but not advance/fast forward the video. I have tried to get the template youtube iframe code (https://developers.google.com/youtube/iframe_api_reference) working within Qualtrics, but that doesn't seem to work as it seems to ignore the javascript, unless I'm missing something basic (which honestly I hope I am). I am putting the javascript in the Qualtrics.SurveyEngine.addOnload function. FWIW, It works just fine as a stand alone page, attached.
I am able to insert the youtube video using just an iframe but again, when I try to use youtube's API function onPlayerStateChange, I can never get that working.
TL;DR. Is there a way that I can detect when a youtube video goes to completion so I can show a question or next button?
I hope this made sense and that someone can point me to what I'm doing wrong, or at least tell me what I'm trying to do isn't possible.
Thanks!
Best answer by mylegshurt
Thanks again @rettweber for giving some suggestions on how to get things working. I did eventually figure it out. In the youtube API example, they create the video player object within a function delcared via:
function onYouTubeIframeAPIReady()
However, that was never being called within Qualtrics until I defined as:
window.onYouTubeIframeAPIReady = function()
Defining onYouTubeIfromAPIReady within the window fixed everything and I can now detect when the video reaches the end (i.e., it's state = end).
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
