How to restrict how many times participant plays uploaded audio

aragorn
aragorn New York, NY Qubie ✭

Hi all,

I have been working on a task involving audio stimuli and a visual analog scale (VAS). After the participant clicks and plays the audio, the participant is supposed to make a judgment of the audio stimulus using a VAS. However, I only want the participants to hear the audio once.

Qualtrics.SurveyEngine.addOnload(function()

{

/*Place your JavaScript here to run when the page loads*/

});


Qualtrics.SurveyEngine.addOnReady(function()

{

/*jQuery('audio').on('ended', function() {

    jQuery(this).css("pointer-events","none");*/

});

Qualtrics.SurveyEngine.addOnUnload(function()

{

/*Place your JavaScript here to run when the page is unloaded*/

});


Above is the code listed in the JS section, per the recommendation of this post. Still doesn't work.

Any tips on how to do this? Thank you!

Tagged:

Answers

  • aragorn
    aragorn New York, NY Qubie ✭

    never mind! it worked!!!

  • rondev
    rondev Wizard ✭✭✭✭✭
    edited June 2020

    Remove /* and */ from start and end. Also add closing brackets });

    So the final code would be just this:

    Qualtrics.SurveyEngine.addOnload(function()
    {
    /*Place your JavaScript here to run when the page loads*/
    });
    
    Qualtrics.SurveyEngine.addOnReady(function()
    {
    jQuery('audio').on('ended', function() {
        jQuery(this).css("pointer-events","none");
    
    });
    });
    Qualtrics.SurveyEngine.addOnUnload(function()
    {
    /*Place your JavaScript here to run when the page is unloaded*/
    });
    
  • aragorn
    aragorn New York, NY Qubie ✭

    thanks @rondev!

  • honsonl
    honsonl WA Qubie ✭
    edited August 2020

    Hi, modifying the code from this post to hide the audio player after clicking "play"

    jQuery('audio').on('play', function() { 
         jQuery(this).hide(); 
    });
    

    I also want to display a string of text afterwards that says "Audio has already been play once. Please select a response." This way, the user would understand what is going on.

    I was thinking that maybe after jQuery(this).hide(), there could be jQuery(message).show()?

    Anyone have any idea, how I can set this up?

  • rondev
    rondev Wizard ✭✭✭✭✭

    @honsonl ,


    Add below code to existing code:

    var that = this.questionId;
    jQuery('audio').on('ended', function() { 
         jQuery("<div> Audio has already been play once. Please select a response.</div>").appendTo("#"+that+" .QuestionText");
    });
    


  • honsonl
    honsonl WA Qubie ✭

    Thanks @rondev for the quickest reply I have ever seen! This works wonderfully. To modify this code, I try to center the message with "style="

    jQuery('audio').on('play', function() { 
         jQuery("<div style="text-align: center;"> <em>Audio has already been played once. Please select a response.</em></div>").appendTo("#"+that+
    " .QuestionText");											
    

    But this gave me an Unexpected Identifier error.

    Any work around?

  • rondev
    rondev Wizard ✭✭✭✭✭

    Wrap text align part with single quotes