There are a few things you need to take into account before commencing this.
Firstly, you need your LimeSurvey to be configured to allow javascript in the question codes. This is done by modifying a config.php file setting. Add the line "$filterxsshtml = false;" to your config file.
Secondly, displaying videos in web pages is fraught with compatibility issues, so you need to have a good hard think about the methods you use, the video formats you use, and the browsers and platforms your users are likely to use.
The most sensible way (in my opinion) is to us YouTube. YouTube displays videos in flash format, and just about everyone who uses the internet has the flash viewer installed. So it's the most likely way of having your videos visible to the most people. The downside is that the videos you use become publicly available, and you'll need to balance this with the advantage of having them highly compatible.
In this case, you start by uploading your video files to YouTube. After uploading each file, YouTube will give you a link to use to watch the video.
Record these links. You will need the URL references in each one.
Now for the fun part. We want to have a question in our survey display (and play) one of these three videos randomly, and to record which video was played as the answer to a question.
We start by creating a new question.
In the Edit Question section, give the question a code, and make it a “Short Text” question type.
Then click on the “LimeFitWin” button (very left hand side of the question toolbar) to edit the question in full screen. Enter any text you want to have displaying in the question, and then click on “Source”, so we can directly edit the HTML source of the question.
At the position you want the videos, type in the following HTML code:
<span id="embedme" />
This span will be used later to replace with the HTML used to display a video.
Click ‘Source’ again to return to WYSIWYG mode, and then click the “LimeFitWin” button again to return to the normal question edit view.
Now, in the “Help” section, follow the same steps to get to the source code view, and enter:
<script type='text/javascript'>
<!--
var browserName=navigator.appName;
var randomnumber=Math.floor(Math.random()*3)+1;
var youtubearray=new Array();
youtubearray[1]='http://www.youtube.com/v/ptYBgsx0W3g&hl=en&fs=1&&autostart=1';
youtubearray[2]='http://www.youtube.com/v/dCdDKEFFU7Q&hl=en&fs=1&&autostart=1';
youtubearray[3]='http://www.youtube.com/v/4QAlt4Sfl7Q&hl=en&fs=1&&autostart=1';
var descriparray=new Array();
descriparray[1]='Who broke up the beatles?';
descriparray[2]='The President Speaks';
descriparray[3]='Lord of the Rings';
var fieldname='answer74223X13X124';
var youtubeurl=youtubearray[randomnumber];
var showme=descriparray[randomnumber];
document.getElementById('embedme').innerHTML='<object width="425" height="344"><param name="movie" value="'+youtubeurl+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+youtubeurl+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>';
if(document.getElementById('answerFIELDNAME') != null) {
document.getElementById('answerFIELDNAME').value=showme;
} else {
document.getElementById(fieldname).value=showme;
document.getElementById(fieldname).style.display='none';
}
//-->
</script>
This script will choose a random number out of 3, then using that number select one of three YouTube videos.
It will load the video and automatically start playing it, and also write the description of the video into the answer for this question.
You will need to make some modifications to the script, at the top where the variables are set.
With the line:
var randomnumber=Math.floor(Math.random()*3)+1;
Change the number 3 to whatever number of videos you are randomly selecting from.
Next, we're setting up a javascript array for each of the three youtube URLs.
var youtubearray=new Array();
youtubearray[1]='http://www.youtube.com/v/ptYBgsx0W3g&hl=en&fs=1&&autostart=1';
youtubearray[2]='http://www.youtube.com/v/dCdDKEFFU7Q&hl=en&fs=1&&autostart=1';
youtubearray[3]='http://www.youtube.com/v/4QAlt4Sfl7Q&hl=en&fs=1&&autostart=1';
Replace the values here with the URLs you copied and saved when uploading your videos to youtube. Add "&autostart=1" to the end if you want the videos to start playing automatically
Then we're creating a javascript array to contain descriptions of each one.
var descriparray=new Array();
descriparray[1]='Who broke up the beatles?';
descriparray[2]='The President Speaks';
descriparray[3]='Lord of the Rings';
Replace these values with brief descriptions of each of the videos. This is what will be saved in the database to tell you which video was watched.
With the line:
var fieldname='answer74223X13X124';
change this to the SGQA code for your question. The simple way to do this is to look at the URL bar of your web browser while editing the question. It will look something like this:
admin.php?action=editquestion&sid=74223&gid=13&qid=124
In this case the value for sid is 74223, gid is 13 and qid is 124. This translates to a code of answer74223X13X124. If your URL said:
admin.php?action=editquestion&sid=55253&gid=99&qid=356
then your code would be “answer55253X99X356”.
Having made all these changes to the help section of your question, return to the normal view (click “Source”, the “LimeFitWin”) and save your new question.
When you preview the question (if all has been done correctly) you will see one of your videos randomly. If you refresh the preview it will randomly choose another. Note that random does not guarantee that consecutive loads will display a different video. You may get 2 or 3 or 4 of the same one in a row. Over a reasonable sample size, however, you should get a fairly even distribution.