Last active
October 23, 2022 16:32
-
-
Save marketinview/5bcc6cb9ff19daa0dbdba11e11a643b4 to your computer and use it in GitHub Desktop.
Qualtrics: Include HTML5 Video. Hide Next button until video finishes. Also fixes preview mode issues. #qualtrics #js #jq #next #hide #video #html5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div style="text-align:center"> | |
<video id="vidId" controls="controls" autoplay="autoplay" width="100%"> | |
<source src="${e://Field/vid_url}" type="video/mp4"> | |
Your browser does not support HTML5 video. | |
</video> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Qualtrics.SurveyEngine.addOnReady(function() { | |
var qobj = this; | |
var video = jQuery("#vidId"); | |
var vidEl = video.get(0); | |
var previousTime = 0; | |
qobj.disableNextButton(); | |
qobj.hideNextButton(); | |
var preview = false; | |
if(/^\/jfe[0-9]?\/preview/.test(window.location.pathname)) preview = true; | |
if(preview) { | |
if(jQuery('.MobilePreviewFrame:first').length > 0) vidEl.muted = true; | |
} | |
video.on('timeupdate', function(event) { | |
if(!vidEl.seeking) previousTime = Math.max(previousTime, vidEl.currentTime); | |
}); | |
video.on('seeking', function(event) { | |
if(vidEl.currentTime > previousTime) vidEl.currentTime = previousTime; | |
}); | |
video.on('ended', function(event) { | |
qobj.enableNextButton(); | |
qobj.showNextButton(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See additional Qualtrics solutions at: https://qualtricswiki.tgibbons.com/doku.php