Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Creating customized play buttons for videos (to add one-minute timer)

  • linden
  • linden's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #207493 by linden
Is it possible to create a button that starts a one-minute timer for a task where participants have to do something? I’ve made a one-minute movie with a timer, counting down to zero from 60 seconds. The play button with the <video> tag in limesurvey is tiny, so I need to make a separate larger button or an overlay button on the video.

I tried to add an overlay with javascript, with something like “press here to start a one-minute timer,” to start the movie with the countdown. Another possibility is to add a separate html button named “START TIMER,” with the video next to the button. The latter solution is below.

I’ve had no success so far. The code below works outside limesurvey on the same web server. In limesurvey, the page reloads and resets less than one second after pressing the play button. I have little experience with javascript and the HTML5 video tag, so I’m not sure what the issue is. Filter HTML for XSS is set to off in the global settings. The javascript seems to work slightly better when adding them in the source code for the questions than adding them in the custom.js file in the template, which is odd.

Does anyone have a solution to this or know what is going on? If possible, I would add something over the video, e.g., an image with “press here to start,” with the option of reloading and pausing the movie with separate buttons.

The following code was entered into the source of a text (mask) question type.
Code:
<video src="path/to/movie/name_of_movie.mp4" width=320 height=240 controls id=videoPlayer>
</video>
 
<div>
  <button id=buttonPlay>Start</button>
  <button id=buttonPause>Pause</button>
  Current time is: <span id="timeDisplay"></span>
</div>
 
<script>
  /* use global variable for ease */
  var v = document.getElementById('videoPlayer');
  /* play button */
  document.getElementById('buttonPlay').addEventListener('click',function(e){ v.play(); },true);
  /* pause button */
  document.getElementById('buttonPause').addEventListener('click',function(e){ v.pause(); },true);
  /* current time display (rounded to nearest second) */
  v.addEventListener('timeupdate',function(e){ document.getElementById('timeDisplay').innerHTML = Math.floor(e.target.currentTime); },true);
</script>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #207516 by tpartner
The buttons are submitting the form because there is no type attribute.

Try:

Code:
<div>
  <button type="button" id=buttonPlay>Start</button>
  <button type="button" id=buttonPause>Pause</button>
  Current time is: <span id="timeDisplay"></span>
</div>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: linden
The topic has been locked.
  • linden
  • linden's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #207738 by linden
Thanks! Confirming that adding type="button" solved the issue.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose