Welcome to the LimeSurvey Community Forum

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

One piece of audio playing uniterrupted across several questions

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago - 1 year 10 months ago #229457 by tpartner
Assuming the the first question is given a class "hidden", this will show that first question when the audio is played:

Code:
<audio autoplay="" controls="" onplay="handleFirstPlay()">
  <source src="pathToMy.mp3" type="audio/mp3" /> 
  Your browser does not support the audio element.
</audio>
<script type="text/javascript" data-author="Tony Partner">  
 
  // Function fired when the player is played
  function handleFirstPlay() {
    if($('.question-container:visible').length == 0) {
      $('.question-container:eq(0)').hide().removeClass('hidden').fadeIn(300);
    }
  }
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 year 10 months ago by tpartner.

Please Log in to join the conversation.

  • paul.emmines
  • paul.emmines's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #229460 by paul.emmines
Thanks Tony, works like a charm!

Please Log in to join the conversation.

  • paul.emmines
  • paul.emmines's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 10 months ago #229696 by paul.emmines
This code is working great! I'd like to smooth the transitions between the first question completing and the second arriving. Where would I put fadeIn and fadeOuts to make this transition more smooth? I tried adding fadeIns to the conditional second questions, and they all then appeared despite the conditions!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #229726 by tpartner
You did not attach a recent .lss example but, as far as I can remember, you are showing the following questions via relevance (conditions). This is done by adding or removing class names, not by directly changing the display style so you cannot add a fade animation.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • paul.emmines
  • paul.emmines's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 9 months ago #230559 by paul.emmines
Thanks for this Tony. I've made an amend and broken it! So I've added a 3 second pause before the questions become visible, so that the participant has to listen to at least 3 secs of the audio before they answer the Q.
However this breaks the if statement, as the Qs aren't visible for 3 seconds, which means that if someone presses pause and play again on the audio player within that 3 seconds, the function can run again and all hell breaks loose. I'm trying to find a way of only allowing the function to run once.

Here's the current code:

// Function unhide the first Q three secs after the player is played
function handleFirstPlay() {
if ($('#question{QID}.question-container:visible').length == 0) {
setTimeout(function() {
$('#question{QID}').hide().removeClass('hidden').fadeIn(300);
}, (3 * 1000));
}
}

I've been trying to set-up something like adding var running = 1 at the beginning of the function, then an if statement of if running!=1 {}, but I'm not having much success.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago - 1 year 9 months ago #230560 by Joffm
The editor drives me crazy

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 9 months ago by Joffm.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #230561 by Joffm
Hi,
1. Are the controls necessary? Remove them

2. You may insert the effect "delay(x)" like
Code:
<audio autoplay="" onplay="handleFirstPlay()">
    <source src="https://www.mafosurvey.de/userfiles/Track06.mp3" type="audio/mp3" />
      Your browser does not support the audio element.
</audio>
 
<script type="text/javascript" data-author="Tony Partner">
     // Function fired when the player is played
    function handleFirstPlay() {
        if($('.question-container:visible').length == 0) {
            $('.question-container:eq(0)').hide().delay(3000).removeClass('hidden').fadeIn(300);
        }
    }
</script>

But as Tony already said, you still did not attach a lss export of this relevant part of your survey.  

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • paul.emmines
  • paul.emmines's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 9 months ago #230564 by paul.emmines
Here's the survey.

Participants have to answer questions on a piece of audio, fired from the Group description.
I'm presenting this survey grp by grp so that same audio can play across the first question and then the subsequent conditionals but making it look like it's presented Q by Q via JS.
It's all working as I was hoping it would (thanks to your help!) except for one issue.  I added the delay to the initial Q, so that participants have to hear 3 seconds of the audio before answering the question.  If the audio is paused and restarted during the delay before the question becomes visible, the function starts again (as the if statement has been met,) which results in the initial question reappearing above the conditional ones.  So what I need is an alternate if statement that doesn't depend on the visibility of the question, and will limit function handleFirstPlay() to only running once (or something else that can achieve that!)
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #230568 by Joffm
Mabe it is an option to hide the group description after the audio started.
$('.group-description').hide();
I tried it an it works fine
Code:
    function handleFirstPlay() {
        $('.group-description').hide();
        if($('.question-container:visible').length == 0) {
....

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • paul.emmines
  • paul.emmines's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 9 months ago #230570 by paul.emmines
I would like the group description to remain in place just in case users want to pause the audio.

Would something like this work - setting a variable to show that the function has run so that it won't run again? This didn't work for me, but I'm probably making a rookie error somewhere!

<script type="text/javascript" data-author="Tony Partner">
// Function fired when the player is played
function handleFirstPlay() {
if (hasitrun != 1) {
var hasitrun = 1;
$('.question-container:eq(0)').hide().delay(3000).removeClass('hidden').fadeIn(300);
}
}
</script>

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago #230573 by Joffm
So probably I misread the word "uninterrupted"

Well, the variable "hasitrun" has to be defined outside the function.
Code:
   var hasitrun;
   // Function unhide the first Q three secs after the player is played
    function handleFirstPlay() {
      if (hasitrun != 1) {
        hasitrun = 1;
        if ($('#question{QID}.question-container:visible').length == 0) {
          $('#question{QID}').hide().delay(3000).removeClass('hidden').fadeIn(300);
        }
      }
    }

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose