Update: Video in Qualtrics not loading properly | XM Community
Skip to main content

Hello all, as in my last discussion post, I am trying to make a video in Qualtrics that has not been loading properly. The video is coded such that it autoplays, is pinned to the top of the page (so that respondents don’t have to scroll down to view it), and can be responded to with the keyboard (e.g., pressing “J” to answer a question about the video). Although this code has worked, when the video loads, it glitches, like so (at the 2 and 7-second marks):

This glitching looks a little different with each test, but regardless, it occurs consistently and on all browsers tested (Chrome, Safari, Firefox). Below is the most recently updated JavaScript and HTML code for the first video in the example attached. Since the last forum post, I have tried removing each code (keyboard responding, autoplaying, and pinning the video) one at a time in varying combinations to see if any one function is the problem, but the issue occurred in all combinations. I would really, really appreciate any help as to what might be wrong! 

<video autoplay="" class="qmedia" height="400" preload="metadata" width="800"><source src="https://unc.az1.qualtrics.com/CP/File.php?F=F_56Y5CBojAj0j0YS" type="video/mp4" /><embed align="middle" autoplay="false" bgcolor="white" class="qmedia" height="400" pluginspage="http://www.apple.com/quicktime/download/" src="https://unc.az1.qualtrics.com/CP/File.php?F=F_56Y5CBojAj0j0YS" type="video/quicktime" width="800" /></video>

 

Qualtrics.SurveyEngine.addOnload(function() {
    var base_element = document.querySelector(".SkinInner");
    base_element.insertAdjacentHTML('afterbegin', '<div id="sticky_vid" style="position: sticky; top:0;" align="middle">');

    var new_element = document.querySelector("#sticky_vid");
    new_element.innerHTML = '<video autoplay class="qmedia" height="400" preload="auto" width="800"><source src="https://unc.az1.qualtrics.com/CP/File.php?F=F_5zp3qW9UH4DmAbc" type="video/mp4" /><embed align="middle"  bgcolor="white" class="qmedia" height="400" pluginspage="http://www.apple.com/quicktime/download/" src="https://unc.az1.qualtrics.com/CP/File.php?F=F_5zp3qW9UH4DmAbc" type="video/quicktime" width="800" /></video>';

    base_element.style.zIndex = 1;
    new_element.style.zIndex = 10;

    this.hideNextButton();
    this.hidePreviousButton();

    var that = this;
    document.addEventListener('keydown', function keydownCallback(e) {
        var choiceID = null;
        switch (e.keyCode) {
            case 74: // 'J' was pressed
                choiceID = 1;
                break;
            case 75: // 'K' was pressed
                choiceID = 2;
                break;
        }
        if (choiceID) {
            document.removeEventListener('keydown', keydownCallback);
            that.setChoiceValue(choiceID, true);
            that.clickNextButton();
        }
    });
});


Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Place your JavaScript here to run when the page is unloaded*/

@V.E. ,

i don’t think the problem has anything to do with your code. I think the issue is hosting it on Qualtrics. Try moving it to another server.


Hi @TomG, I appreciate your insight! I have tried running the issue on other computers (and it persisted), if that is what you mean. Or do you mean using another survey platform entirely? Thanks!


No, I mean you’ve stored the video file in your Qualtrics library. Qualtrics does not work well as a video hosting service. Upload the video to a different web server and change the video url appropriately in your code. 


@TomG that makes sense, thanks! Unfortunately, the video is no longer loading. Is there anything wrong in the below revised HTML/Javascript code? Thank you!!

 

<video autoplay="" class="qmedia" height="400" preload="metadata" width="800"><source src="https://youtu.be/5QAg21KgdhM" type="video/mp4" /><embed align="middle" autoplay="false" bgcolor="white" class="qmedia" height="400" pluginspage="http://www.apple.com/quicktime/download/" src="https://youtu.be/5QAg21KgdhM" type="video/quicktime" width="800" /></video>

 

Qualtrics.SurveyEngine.addOnload(function() {
    var base_element = document.querySelector(".SkinInner");
    base_element.insertAdjacentHTML('afterbegin', '<div id="sticky_vid" style="position: sticky; top:0;" align="middle">');

    var new_element = document.querySelector("#sticky_vid");
    new_element.innerHTML = '<video autoplay class="qmedia" height="400" preload="auto" width="800"><source src="https://youtu.be/5QAg21KgdhM" type="video/mp4" /><embed align="middle"  bgcolor="white" class="qmedia" height="400" pluginspage="http://www.apple.com/quicktime/download/" src="https://youtu.be/5QAg21KgdhM" type="video/quicktime" width="800" /></video>';

    base_element.style.zIndex = 1;
    new_element.style.zIndex = 10;

    this.hideNextButton();
    this.hidePreviousButton();

    var that = this;
    document.addEventListener('keydown', function keydownCallback(e) {
        var choiceID = null;
        switch (e.keyCode) {
            case 74: // 'J' was pressed
                choiceID = 1;
                break;
            case 75: // 'K' was pressed
                choiceID = 2;
                break;
        }
        if (choiceID) {
            document.removeEventListener('keydown', keydownCallback);
            that.setChoiceValue(choiceID, true);
            that.clickNextButton();
        }
    });
});


Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Place your JavaScript here to run when the page is unloaded*/

});


@TomG Sorry to follow up on this, but any idea with my previous response? Thanks for your continued help! I really appreciate it!!


You can’t load a YouTube video in an html5 video tag. You need to use an i frame and the YouTube API.


@TomG Got it, sorry for the confusion! Having used the YouTube API, the glitching issue is now gone, but I’ve noticed that the video now takes a substantial amount of time to load (which is an issue because this is part of a cognitive task, so it needs to happen seamlessly and quickly), and I am also trying to find a way to hide the Youtube logo/user name:

 

 

My Javascript/HTML code to try to do this is below. Thank you!

 

Qualtrics.SurveyEngine.addOnload(function() {
    var base_element = document.querySelector(".SkinInner");
    base_element.insertAdjacentHTML('afterbegin', '<div id="sticky_vid" style="position: sticky; top:0;" align="middle">');

    var new_element = document.querySelector("#sticky_vid");
    new_element.innerHTML = '<video autoplay class="qmedia" height="400" preload="auto" width="800"><source src="https://youtu.be/5QAg21KgdhM" type="video/mp4" /><embed align="middle"  bgcolor="white" class="qmedia" height="400" pluginspage="http://www.apple.com/quicktime/download/" src="https://youtu.be/5QAg21KgdhM" type="video/quicktime" width="800" /></video>';

    base_element.style.zIndex = 1;
    new_element.style.zIndex = 10;

    this.hideNextButton();
    this.hidePreviousButton();

    var that = this;
    document.addEventListener('keydown', function keydownCallback(e) {
        var choiceID = null;
        switch (e.keyCode) {
            case 74: // 'J' was pressed
                choiceID = 1;
                break;
            case 75: // 'K' was pressed
                choiceID = 2;
                break;
        }
        if (choiceID) {
            document.removeEventListener('keydown', keydownCallback);
            that.setChoiceValue(choiceID, true);
            that.clickNextButton();
        }
    });

    // Additional code to hide YouTube logo/user tag
    var iframe = document.querySelector('iframe');
    iframe.addEventListener('load', function() {
        var player = iframe.contentWindow.document.querySelector('.ytp-watermark');
        if (player) {
            player.style.display = 'none';
        }
    });
});
 

<iframe style="pointer-events: none" width="800" height="400" src="https://www.youtube.com/embed/5QAg21KgdhM?autoplay=1&controls=0&disablekb=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; showinfo=0&amp;clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>


Leave a Reply